Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.8K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda