Angular 5 到 6 升级:Observable 类型上不存在属性“地图" [英] Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

查看:12
本文介绍了Angular 5 到 6 升级:Observable 类型上不存在属性“地图"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将我的 angular 应用程序从版本 5 升级到了 6,我从以下代码中收到了这个错误.

 const request = this.evidenceService.get().map((res) => res.data).catch(error => Observable.of(null));

<块引用>

'Observable' 类型不存在属性 'map'.

解决方案

在 RXJS v6 中,运算符链接已经过渡到使用 .pipe(),您应该遵循 推荐的 RXJS 迁移路径.此外,catch 运算符已重命名为 catchError.

现在应该这样做:

const request = this.evidenceService.get().pipe(map((res) => res.data)),catchError(error => Observable.of(null)));

Ive upgraded my angular application from version 5 to 6 and im getting this error from the following code.

  const request = this.evidenceService.get().map((res) => res.data)
                .catch(error => Observable.of(null));

Property 'map' does not exist on type 'Observable'.

解决方案

Operator chaining has been transitioned to the use of .pipe() in RXJS v6, you should follow the recommended migration path for RXJS. Additionally, the catch operator has been renamed to catchError.

Here is how it should be done now:

const request = this.evidenceService.get().pipe(
    map((res) => res.data)),
    catchError(error => Observable.of(null))
  );

这篇关于Angular 5 到 6 升级:Observable 类型上不存在属性“地图"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆