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

288
Visualizações
How to delay call function without setTimeout ? Angular

I need to delay call of function for few seconds. I have solution which work but enough good.

  public recieveNewContact() {
      this.allData();
      setTimeout(() => {  
         this.lastAddedItem()
      }, 100)
  }


  public ngOnInit() { 
    this.allData()
  }

  allData() {
      this.accountsService.getContactPerson().subscribe(
         (data) => {
             console.log(data)
        }
      )
    }

This is work good but i don't like this... I need better solution maybe with rxjs ? Delay ?

which is very important.

In this case, I don't need this:

  allData() {
      this.accountsService.getContactPerson().subscribe(
         (data) => {
             console.log(data)
             this.lastAddedItem()
        }
      )
    }

Because i wan't to load lastAddedItem() on init.... Only when is recieveNewContact triggered.

I will try to explain once again:

  public recieveNewContact() {
      this.allData(); 
      this.lastAddedItem()// here to be called when is allData finished without setTimeout
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I would suggest to use either delay (if you are 100% sure of the completation time) or finalize (if you want to be sure it will wait no matter how long it takes) (rxjs).

Is it necessary to call allData function everytime since you can keep local copy of data in variable and then do the adjustment on it? Or is lastAddedItem API call?

Also I would suggest to set allData as private since don't want it to be called from teplate or another component.

about 4 years ago · Juan Pablo Isaza 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