Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.8K
Views
How to call a function after previous function is complete in angular

I have 2 functions and I would like to call one after the other

mainFunction(){
this.service1.abc();
this.xyz();
}

this.service1.abc is making an API call to get and setting some data in local storage and based on that this.xyz is using that localStorage value. current behavior : this.xyz() get called before the completion of this.service1.abc() and so on localstorage is not getting set.

API Service function doesn't returns any observable,

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

since the API call function is asyncronous you can't just call it in certain order and expect it to be executed in that order.

if your API Service function returns a promise you can do something like this:

   async mainFunction() {
    await this.service1.abc();
    this.xyz();
    }

which will make the function to wait till your async call has finished then move on to execute the XYZ function.

if your API Service function returns an observable, then your can just subscribe to it and trigger your xyz function like that:

mainFunction(){
this.service1.abc().subscribe(res => {
   this.xyz();
})

}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!