Toggle checkbox to simulate and check / uncheck a checkbox in Angular
I have the following HTML:
<li ng-repeat="test in lists.Tests">
<label>
<input type="checkbox" id="cbxAcceptTest" ng-checked="{{test.IsAccepted}}" ng-click="testSelection($event,{{test}})" />
</label>
</li>
and testSelection method like:
$scope.testSelection = function ($event, test) {
if (test.IsAccepted) {
alert('accept');
}
else {
alert('reject');
}
};
I cannot call this method on ngClick, it works on ngChecked, but then I have to use the ngModel Ive read does not go with ngChecked in the following link .
+3
source to share
3 answers
In my case, I have something like this:
<li ng-repeat="item in items">
<label>
<input type="checkbox" ng-model="item.auto" ng-click="onAutoClick(item)" />
</label>
</li>
In my controller:
$scope.onAutoClick = function(item) {
if(item.auto){
// checked (true condition)
} else {
// unchecked ( false condition)
}
};
+1
source to share