如果在Angular 6中遇到了异步自动完成无法工作的问题,但是显示了项目而不更改值,可能是由于以下原因之一:
search = (text$: Observable) =>
  text$.pipe(
    debounceTime(200),
    distinctUntilChanged(),
    switchMap(term =>
      this.myService.searchItems(term).pipe(
        map(response => response.items)
      )
    )
  );
 searchItems(term: string): Observable {
  return this.http.get('api/items?term=' + term)
    .pipe(
      map(response => response.json())
    );
}
 
  {{ r.name }}
 
确保ngbTypeahead指令正确引用了匹配的模板:
如果上述方法仍然无法解决问题,可以尝试从头开始重新创建自动完成组件,确保正确设置和绑定所有的参数和事件。
                    上一篇:Angular 6验证数字输入
                
下一篇:Angular 6异常处理