angular – 如何使用list-formatter示例ng2-auto-complete?

前端之家收集整理的这篇文章主要介绍了angular – 如何使用list-formatter示例ng2-auto-complete?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用list-formatter功能进行ng2-auto-complete,但无法找到如何实现它的一个很好的例子.到目前为止,我有以下代码

@H_403_11@<input class="form-control input-list" ng2-auto-complete [(ngModel)]="model4" placeholder="Search" [source]="googleGeoCode" list-formatter="myListFormatter" path-to-data="" value-property-name=null display-property-name=null min-chars="2" /> export class HomeComponent { templateStr: any = templateStr; valuePropertyName: string; displayPropertyName: string; googleGeoCode: string = "http://localhost:61227/machine/?query=:keyword"; myListFormatter(data: any): string { let html: string = ""; html += data[this.valuePropertyName] ? `<b>(${data[this.valuePropertyName]})</b>` : ""; html += data[this.displayPropertyName] ? `<span>${data[this.displayPropertyName]}</span>` : data; return html; } }

那么,我怎样才能使list-formatter工作?

解决方法

list-formatter属性名必须在括号内,如下所示:

@H_403_11@[list-formatter]="myListFormatter"

函数中的this.valuePropertyName也不会被识别.你必须在引号内放入数据对象的键.

我认为默认值是’id’和’value’.试试数据[‘id’]和数据[‘value’]

猜你在找的Angularjs相关文章