Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular wait for rest API response in subscribe

When I Try to get REST API Call thow client side (Angular) but when i subscribe this at that time function will runing not wait for response so please help for hold on function.

GetLookup(){
  let Country = this.countryService.GetAllCountry().toPromise();
}

OR

GetLookup(){
 this.countryService.GetAllCountry().subscribe((obj){
  let Country = obj;
})
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You Can Use async-await concept.

    async GetLookup(){
  let Country = await this.countryService.GetAllCountry().toPromise();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading