简体   繁体   中英

How to toggle a Boolean on checkbox in Angularjs

I am working on the following code. How can I toggle the state of the Boolean, here isChecked through controller in Angularjs checkbox?

<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>

You can simply check for the changes in your checkbox model:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM