简体   繁体   English

选中Angular Material中的All复选框功能

[英]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? 如何使用Angular材质的标签实现全选复选框功能?

The easiest way is probably to react on the change of your "select all" checkbox with ng-change and modify your array. 最简单的方法可能是使用ng-change对“全选”复选框的更改做出反应并修改数组。

<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. 手动或使用lodash的_.forEach遍历数组, 然后在数组中设置值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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