0
完成我使用奧弗的自動完成在Angular2應用打開汽車上點擊按鈕
https://github.com/oferh/ng2-completer
我希望有一個行爲,其中自動完成不會在打字自動打開,但我需要按下一個按鈕,只那麼應該自動完成做一個服務器請求並顯示我試圖執行CompleterData下拉:
import { Http, Response } from "@angular/http";
import { Subject } from "rxjs/Subject";
import { HttpClient } from './shared';
import { CompleterData, CompleterItem } from 'ng2-completer';
export class AddressData extends Subject<CompleterItem[]> implements CompleterData {
private url: string;
constructor(private http: HttpClient, public erpIDParent: number, url: string) {
super();
this.url = url;
}
public setErpIDParent(erpIDParent: number) {
this.erpIDParent = erpIDParent;
}
public search(term: string): void {
console.log('searching');
if (this.erpIDParent > 0) {
this.http.get(`${this.url}${term}&erpIDParent=${this.erpIDParent}`)
.map((res: Response) => {
// Convert the result to CompleterItem[]
let data = res.json();
let matches: CompleterItem[] = data.map((address: any) => {
return {
originalObject: address,
title: address.Name
}
});
console.log(matches);
this.next(matches);
})
.subscribe();
}
}
public cancel() {
// Handle cancel
}
}
,不停的minSearchLength 1000
<ng2-completer placeholder="{{ 'NewOrder.typeToSearch' | translate }}" formControlName="address" [(ngModel)]="address" [datasource]="addressDataService" (selected)="addressSelected($event)" [minSearchLength]="1000"></ng2-completer>
所以它不會向服務器發送請求,然後我按一下按鈕我有這樣的代碼:
searchAddresses() {
this.addressDataService.search(this.address);
}
因此將手動啓動搜索,但它似乎沒有工作,我想要的方式至。下拉菜單顯示並立即隱藏。有沒有什麼辦法解決這一問題?
優秀。謝謝 :) –