I have the following directive which uses two lists: listGroup
and listAll
.
They are JSON objects like this:
$scope.usersGroup = [
{ id: '1', name: 'User 1' },
{ id: '2', name: 'User 2' },
{ id: '3', name: 'User 3' }
]
I want to add a class to each item if item
is already in userGroup
:
JS:
.directive('tableList', function() {
return {
restrict: 'EA',
template: '<--SOME CODE' +
'<tr class="ADD CLASS IF ITEM IS IN LISTGROUP" ng-repeat="item in listAll">' +
'<th scope="row"><input type="checkbox" value="0" ng-model="item.selected"></th>' +
'<td><a href="#/groups/{{item.id}}">{{item.name}}</a></td>
'MORE CODE-->',
scope: {
listName: "@",
listGroup: "=",
listAll: "=",
submit: "&"
},
controller: function() {},
link: function(scope, elem, attr, ctrl) {
scope.checkAll = function() {
if (scope.selectedAll) {
scope.selectedAll = false
} else {
scope.selectedAll = true
}
angular.forEach(scope.listAll, function(item) {
item.selected = scope.selectedAll
})
}
}
};
})
HTML:
<table-list
list-name="users"
list-group="usersGroup"
list-all="usersAll"
submit="submit()">
</table-list
What's the AngularJS-way of doing this?