Search code examples
angularjsangularjs-scope

Select All Checkbox scope variable not getting set


I want to implement the functionality of "select All" checkbox should get selected when we select all the sub-items.

PlnkrHere is the plnkr.

why the "select All" model is not getting set?


Solution

  • Change your select method to this:

    $scope.select = function(){
        angular.forEach($scope.friends, function (item) {
            if(!item.Selected){ // uncheck 'all' if any item is not selected
                $scope.selectedAll = false;
            }
        });
    };
    

    UPDATE

    You can remove the select method entirely, 'check all' is handled in the isSelected method.