从5到6的角度升级:Observable类型不存在属性"map" [英] Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

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

问题描述

我已经将我的角度应用程序从版本5升级到了版本6,并从以下代码中获取了此错误.

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'.

推荐答案

在RXJS v6中,操作员链接已转换为使用.pipe(),您应遵循

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.

这是现在应该怎么做:

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

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

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