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