1
我正在使用角4与材料2.角2材料,自动完成与远程数据
我已经成功地创建了一些使用数组数组的自动完成字段。在这里我的控制器:
sectorCtrl;
allSectors
filteredSectors: any;
constructor() {
this.sectorCtrl = new FormControl();
this.filteredSectors = this.sectorCtrl.valueChanges
.startWith(null)
.map(name => this.filterValues(name));
}
filterValues(val: string) {
return val ? this.allSectors.filter(s => new RegExp(`^${val}`, 'gi').test(s.label)) : this.allSectors;
}
而且我的模板:
<md-input-container>
<input mdInput placeholder="Sectors" [mdAutocomplete]="auto" [formControl]="sectorsCtrl">
</md-input-container>
<md-autocomplete #auto="mdAutocomplete" [displayWith]="displayFn">
<md-option *ngFor="let value of filteredSectors | async" [value]="value" >
{{ value.label }}
</md-option>
</md-autocomplete>
我怎么能适应的代码,以便使用远程API?
我认为(我自己也遇到了同样的问题)@Bagbyte希望使用远程API来执行过滤。所以数据应该在'valueChanges'上获取 – GregoryHouseMD