I have list of items and want to assign checkbox to all these items. I have tried the below code but it's not working as expected. If I click on select all; then only select all is getting checked and if I click on any other items then all items are getting checked.
<div class="select">
<input type="checkbox" ng-model="selectAll"
ng-init="selectAll=false;" class="filled-in"
id="userprofiles"/>
<label for="userprofiles">Select all</label>
</div>
<ul class="collection">
<li class="collection-item" ng-repeat="profile in userprofiles">
<input ng-model="user.profile"
ng-init="user.profile=false"
class="filled-in" type="checkbox"
id="userprofile"
value=""/>
<label for="userprofile"> </label>
</li>
</ul>
Controller.js:
$scope.user.profile = [];
$scope.$watch('selectAll', function(newValue, oldValue) {
angular.forEach($scope.userprofiles, function(selected, item) {
$scope.user.profile[item] = newValue;
});
});
Aucun commentaire:
Enregistrer un commentaire