-1

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?

  • take a look at [switchMap](https://www.learnrxjs.io/learn-rxjs/operators/transformation/switchmap) – robert Jun 21 '22 at 22:29

1 Answers1

0

Use switchMap operator:

this.service.getSomething().pipe(
    switchMap(result1 => this.service.getSomething2())
)
Some random IT boy
  • 7,569
  • 2
  • 21
  • 47