如何在单击时将垫子选择重置为初始状态?

发布于 2025-02-07 18:10:25 字数 770 浏览 3 评论 0原文

我正在使用Mat-Select带有Mat-Option,但是我想重置Mat-Option在单击按钮时选择的。因此,我不仅将其值设置为null,我希望该选项在屏幕上显示没有值。

示例:

<div ngIf="listAccounts">
  <mat-select [(value)]="accountSelected">
     <mat-option>Select an option... </mat-option>
     <mat-option [value]="account" *ngFor="let account of listOfAccounts" (click)="yourFunction(account)"> 
       Account {{account.accountNumber}} Agency {{account.agencyNumber}} Digit{{account.digitNumber}} 
     </mat-option>
</mat-select>
<div>
<button (click)="listedAccounts = !listedAccounts"> Button </button>


每次我单击按钮时,我都想Mat-Option转到“选择一个选项...”或一个空选项。

I'm using mat-select with mat-option but I want to reset the mat-option selected when I click on a button. So instead of just set its value to null, I want the option without value to be displayed on the screen.

Example:

<div ngIf="listAccounts">
  <mat-select [(value)]="accountSelected">
     <mat-option>Select an option... </mat-option>
     <mat-option [value]="account" *ngFor="let account of listOfAccounts" (click)="yourFunction(account)"> 
       Account {{account.accountNumber}} Agency {{account.agencyNumber}} Digit{{account.digitNumber}} 
     </mat-option>
</mat-select>
<div>
<button (click)="listedAccounts = !listedAccounts"> Button </button>


Everytime I click on the button I want to mat-option go to "Select an option..." or an empty option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丘比特射中我 2025-02-14 18:10:25

只需将空值设置为accountsclected,然后在mat-option中更改

<mat-option value=''>Select an option... </mat-option>

just set empty value to accountSelected and change in mat-option

<mat-option value=''>Select an option... </mat-option>
夜夜流光相皎洁 2025-02-14 18:10:25

将初始值添加到“重置”按钮上单击的单击使用多选择下拉

html

          <mat-select
            placeholder="{{ generalAppSettings?.filterVariables?.regionText }}"
            (selectionChange)="onRegionChange($event)"
            class="dropdownFilters"
            *ngIf="generalAppSettings.filterVariables.showRegionFilter"
            [(value)]="regionValue"
          >
            <mat-option
              *ngFor="
                let option of generalAppSettings.filterVariables?.continents
              "
              [value]="option.region"
            >
              {{ option.region }}
            </mat-option>
          </mat-select>

          <mat-select
            placeholder="{{ generalAppSettings?.filterVariables?.countryText }}"
            (selectionChange)="onCountryChange($event)"
            class="dropdownFilters"
            *ngIf="generalAppSettings.filterVariables.showRegionFilter"
            [(value)]="initialCountryValue"
          >
            <mat-option *ngFor="let country of countryValue" [value]="country">
              {{ country }}
            </mat-option>
          </mat-select>

      <button
        class="btn btn--primary mat-button-cta"
        (click)="clearFilters()"
      >
        {{ generalAppSettings.filterVariables.resetInfo }}
      </button>

typescript

clearFilters(): void {
    this.initialCountryValue = '';
    this.regionValue = '';
  }

Add the initialvalue to empty on Reset button click with multi select dropdowns

HTML

          <mat-select
            placeholder="{{ generalAppSettings?.filterVariables?.regionText }}"
            (selectionChange)="onRegionChange($event)"
            class="dropdownFilters"
            *ngIf="generalAppSettings.filterVariables.showRegionFilter"
            [(value)]="regionValue"
          >
            <mat-option
              *ngFor="
                let option of generalAppSettings.filterVariables?.continents
              "
              [value]="option.region"
            >
              {{ option.region }}
            </mat-option>
          </mat-select>

          <mat-select
            placeholder="{{ generalAppSettings?.filterVariables?.countryText }}"
            (selectionChange)="onCountryChange($event)"
            class="dropdownFilters"
            *ngIf="generalAppSettings.filterVariables.showRegionFilter"
            [(value)]="initialCountryValue"
          >
            <mat-option *ngFor="let country of countryValue" [value]="country">
              {{ country }}
            </mat-option>
          </mat-select>

      <button
        class="btn btn--primary mat-button-cta"
        (click)="clearFilters()"
      >
        {{ generalAppSettings.filterVariables.resetInfo }}
      </button>

Typescript

clearFilters(): void {
    this.initialCountryValue = '';
    this.regionValue = '';
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文