Rxjs:带有可出租运营商的缺少属性错误 [英] Rxjs: Missing property error with lettable operators

查看:79
本文介绍了Rxjs:带有可出租运营商的缺少属性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用可操作的操作符升级到Angular 5.0.0后,在我的import语句中,出现此错误.

I'm trying to use Lettable Operators in my import statement after upgrading to Angular 5.0.0 and I get this error.

ERROR in src/app/components/hero-detail/hero-detail.component.ts(32,8): error TS2339: Property 'switchMap' does not exist on type 'Observable<ParamMap>'.

我从import "rxjs/add/operator/switchMap"更改为import { switchMap } from "rxjs/operators"

如果在此代码块上失败:

If fails on this code block:

  ngOnInit(): void {
    this.route.paramMap
      .switchMap((params: ParamMap) =>
        this.heroService.getHero(+params.get("id")),
      )
      .subscribe(hero => (this.hero = hero));
  }

有什么想法吗?

推荐答案

感谢@ Jota.Toledo,我使用管道重写了代码块.这是工作代码.

Thanks to @Jota.Toledo, I rewrote the code block using pipe. Here is the working code.

  ngOnInit() {
    console.log(this.route.paramMap);
    this.route.paramMap
      .pipe(
        switchMap((params: ParamMap) =>
          this.heroService.getHero(+params.get("id")),
        ),
      )
      .subscribe(hero => (this.hero = hero));
  }

这篇关于Rxjs:带有可出租运营商的缺少属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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