1

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

1 Answer 1

1

You Can Use async-await concept.

    async GetLookup(){
  let Country = await this.countryService.GetAllCountry();
}
1
  • 1
    Angular is full plenty of Observables. Has no sense pass to Promise and use async. It's a work-around unnecessary
    – Eliseo
    Commented Feb 6, 2023 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.