[英]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.