angularjs - radio group enum
http://angularjs.org/
HTML
<script src="http://www.bootstrapcdn.com//twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://www.bootstrapcdn.com//twitter-bootstrap/2.1.1/css/bootstrap.min.css">
<script src="angular.min.js"></script>
<div ng-controller="MyCtrl"> <span ng-bind="item2.myvalue"></span>
<div style="margin:20px; border: 1px solid green;">
<table>
<tr>
<td>
<buttons-radio class="btn-group" data-toggle="buttons-radio" model="item2.myvalue" options='myOptions'></buttons-radio>
</td>
</tr>
</table>
</div> <span ng-bind="item2.myvalue"></span>
<div style="margin:20px; border: 1px solid green;">
<table>
<tr>
<td>
<label ng-repeat="enumItem in myOptions">
<input type="radio" ng-model="item2.myvalue" ng-value="{{enumItem.Value}}" name="radio" id="enumItem{{enumItem.Value}}" /> <span>{{enumItem.Text}} {{$index}}</span>
</label>
</td>
</tr>
</table>
</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.directive('buttonsRadio', function () {
return {
restrict: 'E',
scope: {
model: '=',
options: '='
},
controller: function ($scope) {
$scope.activate = function (option) {
$scope.model = option.Value;
};
},
template: "<button type='button' class='btn' " +
"ng-class='{active : option.Value == model}'" +
"ng-repeat='option in options' " +
"ng-click='activate(option)'>{{option.Text}} " +
"</button>"
};
});
myApp.controller("MyCtrl", function ($scope) {
$scope.myOptions = [{
Text: "Value1",
Value: 1
}, {
Text: "Value2",
Value: 2
}];
$scope.item2 = {
myvalue: 1
};
});