Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Angular8/Material在mat Select中添加全选触发器_Angular_Angular Material - Fatal编程技术网

如何使用Angular8/Material在mat Select中添加全选触发器

如何使用Angular8/Material在mat Select中添加全选触发器,angular,angular-material,Angular,Angular Material,我创建了以下代码: <mat-form-field appearance="outline"> <mat-label>Handler Type</mat-label> <mat-select multiple [(value)]="handlerType"> <mat-option *ngFor="let handlerType of handlerTypeSelect" [va

我创建了以下代码:

      <mat-form-field appearance="outline">
        <mat-label>Handler Type</mat-label>
        <mat-select multiple [(value)]="handlerType">
          <mat-option *ngFor="let handlerType of handlerTypeSelect" [value]="handlerType">
            {{ handlerType.name }}
          </mat-option>
          <div class="etc-select-action-button">
            <button mat-button color="accent" (click)="selectAll()">
              <mat-icon>check_box_outline</mat-icon> <span>Select All</span>
            </button>
            <button mat-button color="accent" (click)="handlerType=undefined; $event.stopPropagation()">
              <mat-icon>check_box_outline_blank</mat-icon> <span>Clear All</span>
            </button>
          </div>
        </mat-select>
      </mat-form-field>


我想有两个按钮,选择所有和清除所有选定的选项。“全部清除”按钮可以正常工作,但“全部选择”按钮不行。请帮忙。谢谢。

单击selectAll方法时,您可以将所有值指定给handletType属性

试试这个:


单击selectAll方法时,可以将所有值指定给handletType属性

试试这个:

selectAllselect:NgModel、values、array{ 选择.update.emitvalues; } 取消全部选择:NgModel{ 选择.update.emit[]; } selectAllselect:NgModel、values、array{ 选择.update.emitvalues; } 取消全部选择:NgModel{ 选择.update.emit[];
}能否共享selectAll方法代码?selectAll:void{this.handlerType=this.selectAll;}能否共享selectAll方法代码?selectAll:void{this.handlerType=this.selectAll;}
selectAll(){
      this.handlerType = this.handlerTypeSelect;
  }