这是我包含自动完成材料的HTML。
<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
检测选择更改,但它无法检测字段最初是否为空,或者在选择项目后将其删除,然后不选择任何内容并将焦点移出输入字段。
我该如何检测到这一点?
我尝试了onkeypress
、ng-change
与ng-model
(不太确定如何使用)和change
,但都没有起作用。库中是否已经存在某些规定,或者我们需要检测更改和输入字段的值?