Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!