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

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

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