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;
})
}

>Solution :

You Can Use async-await concept.

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

Leave a Reply