input[checkBox]
http://docs.ngnice.com/api/ng/input/input%5Bcheckbox%5D
复选框:ng-model为true,即为选中状态(选中后,ng-model置为true)
ng-true-value:设置选中的值
ng-false-value:设置未选中的值
<script> function Ctrl($scope) { $scope.value1 = true; $scope.value2 = 'YES' } </script> <form name="myForm" ng-controller="Ctrl"> Value1: <input type="checkBox" ng-model="value1"> <br/> Value2: <input type="checkBox" ng-model="value2" ng-true-value="YES" ng-false-value="NO"> <br/> <tt>value1 = {{value1}}</tt><br/> <tt>value2 = {{value2}}</tt><br/> </form>
input[radio]
http://docs.ngnice.com/api/ng/input/input%5Bradio%5D
http://docs.ngnice.com/api/ng/directive/ngValue
单选钮:每个radio通过ng-value绑定不同value值。radio选中后,绑定的value值赋给ng-model(ng-model绑定的值为某一个radio绑定的value值,则radio置为选中状态)
<script> function Ctrl($scope) { $scope.names = ['pizza','unicorns','robots']; $scope.my = { favorite: 'unicorns' }; } </script> <form ng-controller="Ctrl"> <h2>Which is your favorite?</h2> <label ng-repeat="name in names" for="{{name}}"> {{name}} <input type="radio" ng-model="my.favorite" ng-value="name" > </label> <div>You chose {{my.favorite}}</div> </form>
注意:改为 $scope.my = ‘unicorns’ ; ng-model = “my” You chose {{my}} 会有问题!