Mona Coder
Mona Coder

Reputation: 6316

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>

Upvotes: 0

Views: 2304

Answers (1)

MuntingInsekto
MuntingInsekto

Reputation: 1593

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);
    };

Upvotes: 3

Related Questions