Jake
Jake

Reputation: 45

wait http request to finish, then use the result in another http request in angular 6

i have to make 2 http requests, the second one depends on the first one's result. How to make it possible ? I tried subscribe and map, but not working. Thank you for yor time

Upvotes: 0

Views: 34

Answers (1)

bryan60
bryan60

Reputation: 29305

hard to show you without your own code but it would look something like this:

this.request1().pipe(
  switchMap(result1 => this.request2(result1.neededProp))
).subscribe(result2 => console.log(result2))

switchmap takes the value from 1 observable response and switches into another observable.

Upvotes: 2

Related Questions