7

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?

1
  • A good thing to remember is that in RXJS Promises can be treated as Observables that will at most emit a single item (the resolved data). Commented Apr 25, 2016 at 14:42

1 Answer 1

8

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
  });
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this answer helped me! +1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.