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

179
Vistas
how to execute methods in ngoninit one after another

I have 4 methods in ngoninit two methods form getting data from api and other two are to load that data on page load example:

ngOnInit(){
getname();
getsubjects();
loadname(); 
loadsubjects();
}
/*this loadname to load reactive forms which is declared in constructor
when I am running this I am getting form value as empty If I put load name() in change or click then values are loading to the form am I missing something here conceptual wise anything or any suggestions ?*/
about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Answer

how to execute methods in ngoninit one after another

As @Optimal says, consider using concat() to do this in combination with what I suggest...

when I am running this I am getting form value as empty If I put load name() in change or click then values are loading to the form am I missing something here conceptual wise anything or any suggestions ?

Observables are used to communicate with backend api services using HTTP from Angular, as data arrives at the frontend asynchronously, and to "capture" this data as soon as it arrives you use subscribe()

Reference to the very clear and helpful Angular doc that explains this

My possible solution

ngOnInit() {

   // 'name' is captured as soon as it "arrives" from the api service
   // 'this.name' is the local (variable) destination of the requested data
   getname().subscribe(name => this.name = name)

   // same for subjects
   getsubjects().subscribe(subjects => this.subjects = subjects)

   // ...
}

should work but it depends on how you implemented the get() methods. If you can, please provide the full code for a better answer


I hope I was helpful, let me know how it goes! :)

about 4 years ago · Santiago Gelvez Denunciar

0

You can use concat to run observables in order.

import { concat } from 'rxjs';


ngOnInit(): void {
    concat(getName(), getSubjects(), loadName(), loadSubjects())
    .subscribe();
}

about 4 years ago · Santiago Gelvez 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