选择更改后从垫选择中移除焦点

Iwo*_*woo 3 select focus angular

在 .html 文件中我有选择器:

<mat-form-field>
    <mat-select #selector(selectionChange)="onSelectionChange($event.value)">
      <mat-option *ngFor="let test of tests" [value]="test">
      </mat-option>
    </mat-select>
  </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

在 .ts 文件中我有:

  @ViewChild('selector', { static: false }) selector: MatSelect

  onSelectionChange(value: any) {
    this.selector.focused = false;
  }
Run Code Online (Sandbox Code Playgroud)

它不起作用,因为 focus 是只读参数,但如何以其他方式实现此效果?

Che*_*pan 7

MatSelect 公开close方法。

尝试这个:

 onSelectionChange(value: any) {
    this.selector.close();
  }
Run Code Online (Sandbox Code Playgroud)