Reputation: 103
I have 2 API calls -- the second call uses something the first call returns. With promises this was easy:
myService.findAll()
// First call
.then(response => {
return myService.findSpecific(response.something);
})
.then(response => {
// result from second API call
});
How would I do this using observables?
Upvotes: 7
Views: 2041
Reputation: 202306
You can leverage the flatMap
operator this way:
myService.findAll()
// First call
.flatMap(response => {
return myService.findSpecific(response.something);
}).subscribe(response => {
// result from second API call
});
Upvotes: 8