On my page I have a three list of checkboxes. Each list has an own checkbox "select all". I do not want to increase code with duplicating lines, that's why I'm using the same function with parameter to select certain list of checkboxes
$scope.selectAll = function(array) {
angular.forEach(array, function(item) {
item.Selected = $scope.model.selectedAll;
});
};
html
<input type="checkbox"
ng-model="model.selectedAll"
ng-change="selectAll(categories)" >
It gives me desirable result, I can select all checkboxes in certain array.
But here is the problem. $scope.model.selectedAll related to all lists and when I select all at the one list, checkbox "select all" is checked in all lists.
I clearly understand this problem, I just don't have any idea how to resolve it. I have been thinking about creating of 3 different variables for each list but I'm using function with parameter, where array is unknown, so I cannot associate certain variable with it and it won't be working.
Is there any way to resolve this problem without duplicating code for particular list of checkboxes?
thanks in advance.
$scope.selectAll()to choose whether to select or deselect instead of looking up a DOM node inside the function?