阅读(2047) (0)

AngularJS 选择状态:checkbox

2017-07-19 11:34:21 更新

它也算是 input 的扩展,不过,它没有验证相关的东西,只有选中与不选中两个值:

<form name="test_form" ng-controller="TestCtrl">
  <input type="checkbox" name="a" ng-model="a" ng-true-value="AA" ng-false-value="BB" />
  <span>{{ a }}</span>
</form>

var TestCtrl = function($scope){
  $scope.a = 'AA';
}

两点:

  • controller 要初始化变量值。
  • controller 中的初始化值会关系到控件状态(双向绑定)。