【发布时间】:2020-10-24 11:49:27
【问题描述】:
我的 component.html(输入字段)
<input type="text" class="form-control" [(ngModel)]="searchQuery" [ngbTypeahead]="recommends"
name="searchQuery" typeaheadOptionField="username">
我的组件.ts
this.recommends = (text$: Observable<string>) => {
return text$.pipe(
debounceTime(200),
distinctUntilChanged(),
switchMap((searchText) => this.stats.getSearchCompletion(searchText))
);
}
我的 getSearchCompletion 函数
getSearchCompletion(searchQuery) {
if(searchQuery) return this.http.post(backendURL + '/my/route', { searchQuery: searchQuery }, { headers: this.headers }).pipe(map(res => res.json()));
}
repsonse 以如下格式返回:
[{
"username": "test"
},
{
"username": "test2"
}]
我收到以下错误: To Image
我猜这是因为我的服务器响应在一个列表中有多个对象。但是如何将 ngbTypeahead 绑定到例如用户名?我试过typeaheadOptionField="username",这给了我错误。列表弹出,但没有条目。
【问题讨论】:
标签: html node.js angular typescript ng-bootstrap