I am modeling my use of switchMap exactly as shown in the Angular documentation:
Angular doc implementation:
ngOnInit() {
this.hero$ = this.route.paramMap
.switchMap((params: ParamMap) =>
this.service.getHero(params.get('id')));
}
My implementation:
ngOnInit() {
let product$ = this.route.paramMap
.switchMap((params: ParamMap) =>
this.getProduct(params.get('id')));
}
My switchmap implementation produces the following error in the editor: (not a runtime error)
[ts]
Argument of type '(params: ParamMap) => void' is not assignable to parameter
of type '(value: ParamMap, index: number) => ObservableInput<{}>'.
Type 'void' is not assignable to type 'ObservableInput<{}>'.
This is my getProduct() method:
private getProduct(id:string) {
this.dataService.getProduct(id).subscribe(product => {
this.product = product;
this.currentImage = product.image[0];
console.log('product = ', this.product)
return of(product);
})
}