簡體   English   中英

如何清除選定的墊選擇

[英]how to clear selected mat-select

在我將選定的值發送到父組件后,我想在選擇后清除選定的 mat-select。

這是我的代碼。

<mat-select
  (selectionChange)="selectEvent($event, InteractionEvent.ADD_ACTIVITY)"
  [(ngModel)]="activityType"
  [(value)]="activityType"
>
  <mat-option [value]="'GATHER'">{{ 'GATHER' | translate | async }}</mat-option>
  <mat-option [value]="'VOTE'">{{ 'VOTE' | translate | async }}</mat-option>
  <mat-option [value]="'RANK'">{{ 'RANK' | translate | async }}</mat-option>
  <mat-option [value]="'SCORE'">{{ 'SCORE' | translate | async }}</mat-option>
</mat-select>
selectEvent(event, type) {
  this.receiveEventOccur.emit({ event: event.value, type: type });
  this.activityType = '';
}

但它沒有在 UI 中更新。

activityType值在 selectionChange 事件發出后設置,快速修復是使用 settimeout,它在設置activityType值后執行this.activityType = ''

selectEvent(event, type) {
  this.receiveEventOccur.emit({ event: event.value, type: type });
  setTimeout(() => this.activityType = '')
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM