Hi, I am able to use the typeahead module on single field by creating an Observable and subscribing to it using a service. However not entirely sure how to use the same Observable for multiple form fields?
For instance i have 3 input fields on which i want to provide the same autocomplete options.
My TS file:
private supplierName1: string = '';
private supplierName2: string = '';
private supplierName3: string = '';
private suppliersListAutoComplete1: Observable<any>;
private suppliersListAutoComplete2: Observable<any>;
private suppliersListAutoComplete3: Observable<any>;
constructor(
private supplierService: SupplierService
) {
this.suppliersListAutoComplete1 = Observable.create((observer: any) => {
this.supplierService.getSuppliersList(this.supplierName1).subscribe((result: any) => {
observer.next(result);
})
});
this.suppliersListAutoComplete2 = Observable.create((observer: any) => {
this.supplierService.getSuppliersList(this.supplierName2).subscribe((result: any) => {
observer.next(result);
})
});
this.suppliersListAutoComplete3 = Observable.create((observer: any) => {
this.supplierService.getSuppliersList(this.supplierName3).subscribe((result: any) => {
observer.next(result);
})
});
}
Anyway i can optimize this code?
No one who had similar scenario? :)
Can anyone please suggest a solution for this problem :(
I suppose at stack overflow its more chances to get an answer
I have the same issue, however I don't have an answer either. I need two different type ahead results
Most helpful comment
Can anyone please suggest a solution for this problem :(