【发布时间】:2020-06-26 15:19:48
【问题描述】:
我正在使用 Angular(9) Powered Bootstrap (ng-bootstrap 6.1) 并为 ngbTypeahead 提供 Observable
search = (text$: Observable<string>) => {
return text$.pipe(
debounceTime(200),
distinctUntilChanged(),
// switchMap allows returning an observable rather than maps array
switchMap((searchText) => {
if (!searchText || searchText.trim().length < 3) {
// when the user erases the searchText
return EMPTY;
} else {
// get a list of dealer reps
return this.myService.getKeyValues(searchText);
}
})
, catchError((error) => of(this.myService.postErrorMessage(error)))
);
}
我需要通过将每个 IKeyValue 项映射到其 item.value 属性来将 this.myService.getKeyValues 的输出从 Observable
如何使用 rxjs 6.5.5 修改上面的代码?
【问题讨论】:
标签: rxjs observable angular9 rxjs6 switchmap