简体   繁体   中英

Select All checkbox Functionality in Angular Material

I am binding the values of checkbox to an array and I need to implement a checkbox that selects all the other checkbox when checked. How can I implement the select All checkbox functionality in Angular material using its tag?

The easiest way is probably to react on the change of your "select all" checkbox with ng-change and modify your array.

<md-checkbox ng-model="ctrl.allSelected" ng-change="ctrl.toggleSelection()" />

Iterate over the array manually or with lodash's _.forEach and set the value in your array.

function toggleSelection() {
    _.forEach($scope.content, function (c) {
        c.selected = $scope.allSelected;
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM