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

标签 javascript angular angular-material radio-button selection

我有 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/

相关文章:

javascript - 将 JSON 对象从 Javascript 发送到 Silverlight,然后触发一个事件来更新 Silverlight

Angular Material Stepper 在第一次加载时未定义

javascript - Angular Material 自动完成与 ngb modal 结合

javascript - 在 PHP 中通过 AJAX 获取或传递敏感数据

javascript - 如何将内部div水平居中于外部div内?

javascript - CSS HTML : Is there workaround for parent scaling and child position:fixed?

angular - 如何以 Angular 5 显示每个 HTTP 请求的微调器?

angular - 无法使用 firestore 解析数据

angular - 如何每隔一段时间发出HTTP请求?

angular - 如何禁止 Angular Material 输入字段的错误输入