如何使用Angular8 / Material在Mat-select中添加全选触发器

时间:2020-03-17 06:43:52

标签: angular angular-material

我创建了以下代码:

id

enter image description here

我想有两个按钮可以选择全部并清除所有选择的选项。全部清除按钮可以正常工作,但全选按钮却不能。请帮忙。谢谢。

2 个答案:

答案 0 :(得分:3)

单击selectAll方法时,可以将所有值分配给handletType属性。

尝试一下:

selectAll(){
      this.handlerType = this.handlerTypeSelect;
  }

答案 1 :(得分:1)

 selectAll(select: NgModel, values, array) {
    select.update.emit(values); 
  }

  deselectAll(select: NgModel) {
    select.update.emit([]); 
  }

尝试

否则

尝试

<mat-checkbox class="mat-option"
                    (click)="$event.stopPropagation()"
                    (change)="selectAll(/* Check to see if you want to check/uncheck all, do that here */)"
                    [indeterminate]="itemsSelected.length && itemsNotSelected.length"
                    [checked]="!itemsNotSelected.length">
        Select All
      </mat-checkbox>