Zachscs Zachscs - 3 years ago 312
HTTP Question

Asynchronous Programming in Angular

How can I use async/await in angular to make asynchronous requests. For example call a function

and only after it resolves call
? I've read examples but still haven't gotten it down and if I could see a basic example where you make one http request and another only after the first one finishes that would help a lot.

Edit: my http requests return observables not promises, maybe async/await isn't the right choice?

Answer Source

Well, if you are suing Http or HttpClient, then post and get methods are returning observable to which you can subscribe, and callback will be always executed asynchronous., body).subscribe(
   (res) => { 
      // you can just simply call another function which will make request
      // or just make another request


private getData() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download