【发布时间】:2019-07-16 06:38:32
【问题描述】:
每当用户开始搜索将调用 HTTP 服务并获取响应并将其显示在下拉列表中时,我都会遇到这样的情况。
我有下面的代码,可以很好地使用上述方法。但是,在我们单击下拉列表中列出的任何选项后,ngmodelchange 方法再次调用 which 再次获取服务。它不应该发生。
我错过了什么?
<mat-form-field class="half-width">
<input matInput aria-label="State" name="state" placeholder="Search by number (1 or 2 or 3)" [matAutocomplete]="auto" [(ngModel)]="currentState"
(ngModelChange) = "filterInstrument(currentState)">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="state">
<mat-option *ngFor="let state of insDetails" [value]="state.id">
<span>{{state.id}}</span> |
<span>{{state.userId}}</span> |
<span>{{state.title}}</span>
</mat-option>
</mat-autocomplete>
</mat-form-field>
stackblitz中的完整代码
【问题讨论】:
标签: javascript html angular angular-material angular6