ng2-ui / auto-complete

Angular Auto Complete component and directive
https://ng2-ui.github.io/dist/#/auto-complete
MIT License
279 stars 123 forks source link

Angular2 ng2-auto-complete display and selection issues #329

Closed skaka30 closed 6 years ago

skaka30 commented 6 years ago

I have implemented the Angular 2 ngui-auto-complete component. And related to this i found example. But the issue I'm facing is, on my auto-complete there multiple dependencies. So for that on selection I want id but I am not getting on selection id.

And one more facing issue is my source is in the form of an object with id as one of the fields. And by following the implementation example of the component, the id is displayed in parenthesis in the dropdown. Is there a way to not display the id in the dropdown?

Here is my HTML code for the auto-complete component: <input class="text-uppercase form-control" ngui-auto-complete [(ngModel)]="shipper.cust_name" [source]="shipperNameSource.bind(this)" value-property-name=null value-formatter="cust_name" min-chars="1" (change)="updateShipperDetails()"/> My component

shipperNameSource = (keyword: any): Observable<any[]> => { let url: string = 'api/getCustomers?selected='+keyword if (keyword) { return this.http.get(url) .map(res => { let json = res.json(); this.customer.id = json.id; return json; }) } else { return Observable.of([]); } } This is what I get

itsashish-patel commented 6 years ago

@skaka30 , Please refer the following solution for your problem

get id based on selection use value change event and you will get selected any object e.g. (valueChanged)="updateShipperDetails($event)" use "list formatter" attribute to display your property e.g. list-formatter="cust_name"

courageDeveloper commented 5 years ago

Thanks a lot @itsashish-patel