我有一个ngbTypeahead,它在字段中键入时应该能够查询对象列表。列表“投影”中对象的形式为
{
code: "6326"
group: "world"
name: "WGS 1984"
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<input id="typeahead-basic" type="text" class="form-control" [(ngModel)]="item.outputProjection.name" [ngbTypeahead]="search" />
Run Code Online (Sandbox Code Playgroud)
在component.ts类中搜索过滤器代码:
search = (text$: Observable < string > ) =>
text$.pipe(
debounceTime(200),
distinctUntilChanged(),
merge(this.focus$),
map(term => (term === '' ? this.projections :
this.projections.filter(v => v.name.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10))
)
Run Code Online (Sandbox Code Playgroud)
当我输入时,我得到的是:
但是我想显示的是json对象中的名称。
另外,bootstrap的人也关闭了它并说这不是错误,而是功能请求:
https://github.com/valor-software/ngx-bootstrap/issues/749
无论平台如何,大多数现代UI控件都可以使用对象。
我正在开发 angular 2 release 6 应用程序和以下代码行:
<input #instance="ngbTypeahead" type="text" class="form-control" [(ngModel)]="item.outputProjection.name" [ngbTypeahead]="search" />
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
DatacartComponent.html:60 ERROR TypeError: Cannot read property 'name' of undefined
at Object.eval [as updateDirectives] (DatacartComponent.html:60)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:11914)
at checkAndUpdateView (core.js:11307)
at callViewAction (core.js:11548)
at execEmbeddedViewsAction (core.js:11511)
at checkAndUpdateView (core.js:11308)
at callViewAction (core.js:11548)
at execEmbeddedViewsAction (core.js:11511)
at checkAndUpdateView (core.js:11308)
at callViewAction (core.js:11548)
Run Code Online (Sandbox Code Playgroud)
而且我不确定如何更好地检查引导程序预先输入的对象定义。