У меня есть список элементов, и я хочу назначить флажок для всех этих элементов.Я пробовал приведенный ниже код, но он не работает, как ожидалось.Если я нажму на выбрать все;тогда только выбрать все проверяется, и если я нажимаю на любые другие элементы, то проверяются все элементы.
<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="{{profile.profile}}"/>
<label for="userprofile"> {{profile.profile_name}}</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;
});
});