Determine if the box is checked or unchecked in the angle change event

I want to determine if the checkbox has been checked or unchecked when a click is made on the flag.

This is what I have:

<input type="checkbox" ng-model="answers[item.questID]" ng-change="stateChanged()" /> 

And then in the controller, I:

 $scope.stateChanged = function () { alert('test'); } 

I can trigger a warning when I check / uncheck the box, but how can I determine the status of the box? I did a little research to find a similar problem, but I could not get what I needed.

Thanks Laziale

+42
javascript jquery angularjs checkbox angularjs-scope
Dec 10 '14 at 22:12
source share
2 answers

You can simply use the bound ng-model ( answers[item.questID] ) answers[item.questID] in your ng-change method to determine if it has been checked or not.

Example: -

 <input type="checkbox" ng-model="answers[item.questID]" ng-change="stateChanged(item.questID)" /> <!-- Pass the specific id --> 

and

 $scope.stateChanged = function (qId) { if($scope.answers[qId]){ //If it is checked alert('test'); } } 
+63
Dec 10 '14 at 22:16
source share

The state of the flag will be reflected on any model with which you are associated, in this case $scope.answers[item.questID]

0
Dec 10 '14 at 10:15
source share



All Articles