0

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>
3
  • Take a look at the docs, it exactly describes what you're looking for docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D Commented Sep 24, 2015 at 0:13
  • Just the change the model itself ($scope.choice = true or false). Commented Sep 24, 2015 at 0:15
  • Why not just use $scope.choice instead of having a separate isChecked variable? If you do that then you probably don't need ng-change or the changeSta function. Commented Sep 24, 2015 at 1:20

1 Answer 1

3

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);
    };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.