如何捕获管道?

Nxt*_*xt3 8 observable rxjs angular rxjs-lettable-operators

如何使用lettable运算符和管道执行以下操作?

    this.httpClient
      .get(url)
      .map((res: any) => {
        const events = res.eventList;
        return events.map(e => new EventLogModel(e));
      })
      .catch(this.handleError);
Run Code Online (Sandbox Code Playgroud)

我试过这个,但是我无法开始catchError工作catchError does not exist on type Observable<any>:

    this.httpClient
      .get(url)
      .pipe(
        map((res: any) => {
          const events = res.eventList;
          return events.map(e => new EventLogModel(e));
        })
      )
      .catchError(this.handleError);
Run Code Online (Sandbox Code Playgroud)

另外,我认为catch并且catchError是一样的,对吗?我这样导入它:

import { map, catchError } from 'rxjs/operators';

但我不确定这是否是正确使用的操作符.

AJT*_*T82 15

你的假设是正确的,可调运算符catchError是相同的catch.

至于放置catchError,它不应该有前缀.,应该放在pipe:

this.httpClient
  .get(url)
  .pipe(
    map((res: any) => {
      const events = res.eventList;
      return events.map(e => new EventLogModel(e));
    }),
    catchError(this.handleError);
  )
Run Code Online (Sandbox Code Playgroud)