Rxjs: Missing property error with lettable operators

丶灬走出姿态 提交于 2019-12-11 15:40:04

问题


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

I changing from import "rxjs/add/operator/switchMap" to 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));
  }

Any ideas?


回答1:


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));
  }


来源:https://stackoverflow.com/questions/47076103/rxjs-missing-property-error-with-lettable-operators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!