gpt4 book ai didi

javascript - 如果用户从 Angular Material 中的单选按钮更改,如何重置下拉值?

转载 作者:行者123 更新时间:2023-12-02 22:45:40 26 4
gpt4 key购买 nike

我有 6 个单选按钮,如下所示:


<mat-radio-button
*ngFor="let option of searchOptions"
[value]="option"
(change)="setSelectedSearchOptions(option.label)"
>
{{ option.label }}
</mat-radio-button>


我有一个像这样的下拉列表:

 <div  class="search-select searchoptions"  *ngIf="showDropdownVcheqCode && selectedSearch">
<mat-select placeholder="Opties" name="option" [(ngModel)]="selectedValueOptie" (ngModelChange) = "reset()" >
<mat-option *ngFor="let option of returnEcheqCodes$ " value="{{option.family}}" > {{ option.title}} </mat-option>
</mat-select>
</div>

因此,如果用户从一个单选按钮切换到另一个单选按钮。必须重置下拉列表中选定的值。

我尝试使用这个函数:

reset(optionLabel: string){
if (optionLabel === 'QrCode') {
this.selectedValueOptie = '';
}

if(optionLabel === 'Vcheq' ) {
this.selectedValueOptie = '';

}

}

但这不起作用。

那么如何实现这个目标?

谢谢

最佳答案

所以首先你必须添加 <option> mat-select 内有空值然后里面reset function只需重置 selectedValueOptie 的值.

HTML

<div class="search-select searchoptions"  *ngIf="showDropdownVcheqCode && selectedSearch">
<mat-select placeholder="Opties" name="option" [(ngModel)]="selectedValueOptie" (ngModelChange) = "reset()" >
<mat-option value="">Please Select</mat-option>
<mat-option *ngFor="let option of returnEcheqCodes$ " value="{{option.family}}" > {{ option.title}} </mat-option>
</mat-select>
</div>

Component // Just unset the value to an empty string

reset(){
this.selectedValueOptie = '';
}

关于javascript - 如果用户从 Angular Material 中的单选按钮更改,如何重置下拉值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58411635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com