handling 2 depending subscriptions? Angular

Fernando Leija Valtierra

I have a component with this code

this.service().subscribe((result) => { this.service2(result).subscribe((result2) => //other code }}

I'm applying good practices in Angular and seems this is not a good approach for this kind of code. But not sure how to improve this.

any suggestion?

Some random IT boy

Use switchMap operator:

this.service.getSomething().pipe(
    switchMap(result1 => this.service.getSomething2())
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related