【问题标题】:Rxjs: Missing property error with lettable operatorsRxjs:可租用运算符缺少属性错误
【发布时间】:2017-11-02 13:04:38
【问题描述】:

升级到 Angular 5.0.0 后,我尝试在导入语句中使用 Lettable Operators,但出现此错误。

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"

如果在此代码块上失败:

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

有什么想法吗?

【问题讨论】:

  • 您使用的 lettable 操作符错误。您需要在管道方法中使用它。您问题中的链接显示了一个示例

标签: angular observable rxjs5


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-08
    • 2020-12-28
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 2015-09-10
    • 1970-01-01
    相关资源
    最近更新 更多