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

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

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 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