你怎么用管子接住?

How do you catch with a pipe?

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

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

我试过了,但我无法让 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);

此外,我假设 catchcatchError 相同,对吗?我是这样导入的:

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

但我不确定这是否是正确的运算符。

你的假设是正确的,lettable 运算符 catchErrorcatch 相同。

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

之内
this.httpClient
  .get(url)
  .pipe(
    map((res: any) => {
      const events = res.eventList;
      return events.map(e => new EventLogModel(e));
    }),
    catchError(this.handleError);
  )