如何在Angularjs中的Checkbox上切换布尔值

时间:2015-09-24 00:09:49

标签: javascript angularjs

请你看一下这个片段,让我知道如何在Angularjs复选框中切换布尔值的状态,这里isChecked通过控制器?

<body ng-app="app">
  <div ng-controller="checkController">
      <input type="checkbox" ng-model="choice" name="item" ng-change="changeSta(choice)" /> Add New Item
  </div>
</body>

<script>
var app = angular.module('app', []);
app.controller('checkController', function($scope) {
   var isChecked = false;
   $scope.changeSta = function() {
     //isChecked = true;
  };

});

</script>

1 个答案:

答案 0 :(得分:3)

您只需检查复选框模型中的更改:

var app = angular.module('app', []);
app.controller('checkController', function($scope) {
    var isChecked = false;
    $scope.changeSta = function() {
        console.log($scope.choice);
    };