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

206
Vistas
Why doesn't the AppComponent have an ngOnInit function by default?

On generating an Angular project using the CLI, the root component - AppComponent does not have an ngOnInit block but every other component generated has an ngOnInit block. Is it wrong to have an ngOnInit in the root component?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There's nothing wrong to have an ngOnInit in the root component. But there is no need.

By the definition, root component is just called once like <app-root></app-root> in the index.html. And not called by any other components. thus, root component would not have @Input() bindings that ngOnInit assured set properly.

not-viable.component.html:

<app-root [someInput]="variable"></app-root>

Conclusion

You can have ngOnInit in the root component, but constructor can do the same thing without any flaw.

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