最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular2 ng2-auto-complete implementation issues - Stack Overflow

programmeradmin3浏览0评论

I have implemented the Angular 2 ng2-auto-plete ponent by following this example. You can access it from here also.

The issue I'm facing 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 ponent, 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-plete ponent:

<input ng2-auto-plete id="inputEvent" class="form-control" [(ngModel)]="model" ngModel
     name="event" #event="ngModel" [source]="items" display-property-name="name" (valueChanged)="onSelect($event)"/>

This is what I get:

I have implemented the Angular 2 ng2-auto-plete ponent by following this example. You can access it from here also.

The issue I'm facing 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 ponent, 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-plete ponent:

<input ng2-auto-plete id="inputEvent" class="form-control" [(ngModel)]="model" ngModel
     name="event" #event="ngModel" [source]="items" display-property-name="name" (valueChanged)="onSelect($event)"/>

This is what I get:

Share Improve this question edited Oct 21, 2016 at 19:48 Stefan Svrkota 50.7k10 gold badges99 silver badges88 bronze badges asked Oct 21, 2016 at 18:48 user3344978user3344978 6541 gold badge8 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You need to set value-property-name attribute to null:

<input ng2-auto-plete id="inputEvent" class="form-control"
[(ngModel)]="model" ngModel name="event" #event="ngModel"
[source]="items" value-property-name=null
display-property-name="name" (valueChanged)="onSelect($event)"/>

value-property-name is optional attribute, but it has default value - id. Setting it to null won't display anything, which is what you are looking to acplish.

you can try ang2-autoplete the live sample is available at : plnkr.co/edit/5zRD0fcOZHXEMOk4kupY?p=preview

发布评论

评论列表(0)

  1. 暂无评论