【发布时间】:2018-01-03 19:03:42
【问题描述】:
我正在使用 Angular Material Autocomplete 根据对远程 API 的搜索列出结果(过滤在远程端完成)。
HTML 方面:
<mat-form-field class="full-width">
<input type="text" placeholder="Brand" aria-label="Number"
matInput [formControl]="formControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let brand of brands | async" [value]="brand.name">
{{ brand.name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
TS方:
this.brands = this.formControl.valueChanges.flatMap(
q => this._apiService.getVehiclesBrands(q).map(x => x.results)
);
此时,一切正常。我从远程获取品牌列表,我可以从自动完成列表中选择一个值。现在的问题是....每次输入文本更改时如何中止所有请求?
有很多关于远程请求的例子,但我们的想法不是在初始化时获得所有远程结果。这个想法是在每次用户更改文本输入时获得远程结果。
【问题讨论】:
标签: angular rxjs angular-material