gpt4 book ai didi

javascript - Angular5 - 如何检测 mat-autocomplete 中的空字段或已删除字段?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:40:49 24 4
gpt4 key购买 nike

这是我的 html,其中包含自动完成的 Material 。

<ng-container *ngSwitchCase="'autocomplete'">
<div [ngClass]="(filter.cssClass || 'col-md-4') + ' mt-2 pt-1'">
<div class="filter-key-label">
{{filter.columnTitle}}
</div>
<div class="filter-form-control d-flex flex-wrap justify-content-left">
<mat-form-field class="full-width">
<input type="text" matInput [formControl]="myControl" [matAutocomplete]="auto" ng-model="blah">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of getOptionsTypeAhead(filter.key) | async" [value]="option" (onSelectionChange)="typeaheadChange($event, filter.key)">
{{ option }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</div>
</ng-container>

目前,我能够使用 onSelectionChange 检测仅选择更改,但它不会检测该字段最初是否为空,或者在选择一个项目然后删除它之后, 我没有选择任何东西并将焦点移出输入字段。

我该如何检测?

我尝试了 onkeypressng-changeng-model(不太确定如何使用它)和 更改 但没有任何效果。图书馆是否已经提供了一些规定,或者我们是否检测到更改并输入了字段值?

最佳答案

解决了!这是change一直。

最好的部分是它的行为不像onkeypress并且只有在出现 blur 时才会触发事件。

我改变了我的 <input>像这样:

<input type="text" matInput [formControl]="myControl" [matAutocomplete]="auto" (change)="handleEmptyInput($event, filter.key)">

Controller 看起来像这样:

handleEmptyInput(event: any, key: string){
if(event.target.value === '') {
delete this.filtersApplied[key];
}
}

就像我想捕获空字段或空白值的实例一样:)

关于javascript - Angular5 - 如何检测 mat-autocomplete 中的空字段或已删除字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49929442/

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