Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.8K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda