2017-06-16 34 views
1

我有以下:支持對象和自定義模板的Angular2/4 typeahead?

[{'title':'Book Title', 'author':'author, 'type':'book'},{'title':'Btitle', 'author':'Bauthor', 'type': 'book'},{'title':'Movie Title', 'author': 'Director', 'type': 'movie'}] 

我想有一個輸入字段(文本),我可以使用類型和顯示一個預輸入。 Ive嘗試過:

ng2-completer - 支持對象,但不支持預覽內容中的自定義模板。

ngx-bootstrap - 不支持對象,但支持自定義模板。

我想要的就是能夠在我的輸入字段中使用自定義模板,並根據數據類型使用自定義值。我怎樣才能做到這一點?或者有什麼支持這個的angular2/4嗎?

回答

1

您可以嘗試使用PRIME NG autocomlete component,它支持對象和模板,與ngModel和反應形式一起使用。

這裏是總理NG的官方例子:

<p-autoComplete [(ngModel)]="brand" 
       [suggestions]="filteredBrands" 
       (completeMethod)="filterBrands($event)"> 
    <ng-template let-brand pTemplate="item"> 
    <div class="ui-helper-clearfix" style="border-bottom:1px solid #D5D5D5"> 
     <img src="assets/showcase/images/demo/car/{{brand}}.png" style="width:32px;display:inline-block;margin:5px 0 2px 5px"/> 
     <div style="font-size:18px;float:right;margin:10px 10px 0 0">{{brand}}</div> 
    </div> 
    </ng-template> 
</p-autoComplete> 
相關問題