首页 > 解决方案 > 在 switchMap 运算符中过滤 Observable

问题描述

我在维基百科搜索中有一个可观察的

https://ng-bootstrap.github.io/stackblitzes/typeahead/http/stackblitz.html

export class NgbdTypeaheadHttp {
  model: any;
  searching = false;
  searchFailed = false;
  myfilter = ['Mary' , 'Maryland'];

  constructor(private _service: WikipediaService) {}

  search = (text$: Observable<string>) =>
    text$.pipe(
      debounceTime(300),
      distinctUntilChanged(),
      tap(() => this.searching = true),
      switchMap(term =>
        this._service.search(term).pipe(
          tap(() => this.searchFailed = false),
          catchError(() => {
            this.searchFailed = true;
            return of([]);
          }))
      ),
      tap(() => this.searching = false)
    )
}

在管道中的 Switchmap 运算符之后,我想过滤掉响应。

要过滤的项目存储在 myFilter 列表中。

我被困在如何做到这一点上。

标签: rxjs

解决方案


推荐阅读