0

I using angular 2 http class https://angular.io/docs/js/latest/api/http/index/Http-class.html for sending post and get request. Now, I want to use send requests synchronously. i.e. second request is send after response of first request. But no option is available for it in angular 2 documentation. So,

How can I send multiple requests synchronously?

In jquery ajax async option is available which handle this type of problem. I am searching for similar option in angular 2.

2

1 Answer 1

1

You can achieve synchronously / await with observables. there is many ways to get this example, this is one option. if you want more check: https://www.learnrxjs.io/operators/transformation/switchmap.html

You have also MergeMap and others

An example:

this.http.get(url1)
.switchMap(
 (response1: Response) => {
          return this.http.url(url2);
})
.subscribe(
   (response2: Response) => {},
   (error: Response) => {},
   () => console.log('completed')
);

Hope its helps you!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.