Angular: Radio inputs
HTML
<script src="http://ci.angularjs.org/job/angular.js-angular-master/232/artifact/build/pkg/0.10.7-64912069/angular-0.10.7-64912069.js"></script>
<form name="form">
<h3>Boolean</h3>
<input type="radio" ng:model="value" name="alias" boolean-value="true" /> true
<input type="radio" ng:model="value" name="alias" boolean-value="false" /> false
CSS
.ng-invalid {
border-color: red;
}
.ng-valid {
border-color: green;
}
.ng-dirty {
border-style: solid;
border-width: 2px;
}
.ng-pristine {
border-style: solid;
border-width: 1px;
}
.errors {
color: red;
}
JavaScript
var myApp = angular.module('myApp', []);
function Main($scope) {
$scope.typeOf = function(value) {
return typeof value;
};
$scope.color = 'red';
$scope.items = [{
name: 'Zero',
email: '[email protected]'
}, {
name: 'One',
email: '[email protected]'
}, {
name: 'Two',
email: '[email protected]'
}, {
name: 'Three',
email: '[email protected]'
}];
}
myApp.directive('booleanValue', function() {
return function(scope, elm, attr) {
attr.$set('value', attr.booleanValue === 'true');
};
});
// this allows binding to
myApp.directive('numberValue', function() {
return function(scope, elm, attr) {
scope.$watch(function() {
return attr.value;
}, function() {
attr.$set('value', parseFloat(attr.value));
});
};
});
myApp.filter('typeOf', function() {
return function(value) {
var type = typeof value;
return type !== 'undefined' ? value + ' (' + type + ')' : '';
};
});