Issue
I using rxjs v. 6.4.0 and am trying to use switchMap to pass the value of my observable to another observable but am getting the error Type 'void' is not assignable to type 'ObservableInput<any>'.
getFoodOrder(id : number): Observable<IFoodOrder> {
let url = `${ this.baseUrl }/food_orders/${ id }`
return this.http.get<IFoodOrder>(url)
}
this.foodOrderProvider.getFoodOrder(1)
.pipe(
switchMap(data => console.log(data)) // <-- error occurs here
).subscribe(() => console.log("done"))
What am I missing? getFoodOrder returns an observable.
Solution
console.log() does not return anything hence the error. Returning data after logging will resolve the error.
switchMap(data => { console.log(data) return of(data)});
If you only want to log the data, better use tap operator, just for looking at the data.
this.foodOrderProvider.getFoodOrder(1)
.pipe(
tap(data => console.log(data))
).subscribe(() => console.log("done"))
Answered By - vaira
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.