问题
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