Issue
I need to assess the result of the first observable to determine if the second one should be subscribed to. From reading other threads and the RxJS documentation I can see that nested subscriptions should be avoided where possible. Below is an example:
obs1().subscribe(result=> {
if (result.status === 'success') {
obs2().subscribe(() => {
executeMethod();
});
}
});
Any help or resources are greatly appreciated.
Solution
It could look like this:
obs1().pipe(
filter(result => result.status === 'success'),
switchMap(() => obs2()),
).subscribe( //...
Answered By - mbojko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.