Is there any RxJS way to conditionally call mergeMap in Angular:
return apiService.myApi.get().pipe(map(res => res), mergeMap(res => this.getPeople(res)))
to something like this:
return apiService.myApi.get().pipe(map(res => res),
someCond ? mergeMap(res => this.getPeople(res)) : null)
No, but you can just return the original value with of()
or use EMPTY
to not emit anything further:
return apiService.myApi.get().pipe(
map(res => res),
mergeMap(res => someCond ? this.getPeople(res) : of(res)),
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.