i have select checkbox , list check-box this.
a checkbox list receive data from
$scope.contacts = [ {"name": "bambizo", "check": false}, {"name": "jimmy", "check": false}, {"name": "tommy", "check": false}, {"name": "nicky", "check": false} ];
i want when check select checkbox, make checkbox in below list checked or unchecked. , here code:
select checkbox:
<input type="checkbox" ng-model="checkallcontact" ng-change="checkallcontact(checkallcontact)">
checkallcontact function:
$scope.checkallcontact = function(){ var allchecked = false; for(i = 0; i< $scope.contacts.length; i++){ if ($scope.contacts[i].check == true){ allchecked = true; }else { allchecked = false; } } if (allchecked = true){ for(i = 0; i< $scope.contacts.length; i++){ $scope.contacts[i].check = false; } }else{ for(i = 0; i< $scope.contacts.length; i++){ $scope.contacts[i].check = true; } } }
but when run , click select checkbox. make error:
how solve or have other way it? thanks
ng-model="checkallcontact"
& method checkallcontact
has same name.
checkallcontact
scope variable overriding checkallcontact
.
you need change function name fix issue.
Comments
Post a Comment