简体   繁体   English

如何在 Angular 中关闭 mat-select-filter 下拉菜单后重置搜索输入值?

[英]How to reset search input value after close mat-select-filter drop-down in Angular?

I am using the mat-select-filter package Link , for searching values from a list using drop-down and I take reference from this Demo .我正在使用mat-select-filter package Link ,使用下拉列表从列表中搜索值,我参考了这个Demo

As shown as Demo link search value is still the same after dropdown close.如图Demo链接搜索值在下拉关闭后还是一样的。

I want to clear or reset the value on the search input field once the dropdown is closed.关闭下拉菜单后,我想清除或重置搜索输入字段上的值。

在此处输入图像描述

As shown in the image "Ita" text is still coming after I select "Italy" from the drop-down.如图所示,“Ita”文本仍然出现在 I select “Italy”之后。 So is there any way to reset the value on search input after selecting the value or after drop-down close?那么有没有办法在选择值或下拉关闭后重置搜索输入的值?

Thanks in Advance.提前致谢。

add (openedChange)="openedChange(matFilterBasic)" on mat-select in html ( this will clear input when select opened or closed )在 html 的 mat-select 上添加(openedChange)="openedChange(matFilterBasic)" (这将在 select 打开或关闭时清除输入)

<mat-form-field>
    <mat-select [disableOptionCentering]="true" #select1 placeholder="Auto Focus" (openedChange)="openedChange(matFilterBasic)">
        <mat-select-filter #matFilterBasic *ngIf="select1.focused" [array]="variables" (filteredReturn)="filteredList2 =$event"></mat-select-filter>
        <mat-option *ngFor="let item of filteredList2" [value]="item">
            {{item}}
        </mat-option>
    </mat-select>
</mat-form-field>

and in ts file add this function (tt is reference from MatSelectFilterComponent )并在 ts 文件中添加此 function (tt 是来自MatSelectFilterComponent的参考)

  openedChange(matFilter: any) {
    matFilter.searchForm.reset();
  }

check example here 在这里查看示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM