Within my webpage, I have three different sets of checkboxes. Each set includes a "select all" checkbox. Instead of repeating code lines, I am implementing a single function with a parameter to select specific checkboxes within each set.
$scope.selectAll = function(array) {
angular.forEach(array, function(item) {
item.Selected = $scope.model.selectedAll;
});
};
Here is the HTML:
<input type="checkbox"
ng-model="model.selectedAll"
ng-change="selectAll(categories)" >
This approach allows me to easily select all checkboxes in a specific array. However, there is an issue - $scope.model.selectedAll
affects all lists, causing the "select all" checkbox to be checked in every list when selected in one.
While I understand the problem, I am unsure how to address it. I have considered creating separate variables for each list, but since the function uses a parameter and the array is unknown, associating a variable with it would not work.
Is there a solution to this problem that does not involve duplicating code for individual sets of checkboxes?
Thank you in advance.