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

255
Views
Angular's ngOnInit vs constructor. What to place In each?

On an Angular 12 componente I have the following:


export class SignUpComponent implements OnInit {

  environment: Environment;
  form: FormGroup;
  stage: number;

  constructor(
    private router: Router, 
    private title: Title, 
    private formBuilder: FormBuilder, 
    private analyticsService: AnalyticsService, 
    private environmentService: EnvironmentService) { 

    this.environment = this.environmentService.get();

    this.title.setTitle('Registar - Bons Alunos');

    this.analyticsService.pageview('Sign Up', this.router.url);

    this.form = this.formBuilder.group({ 
      email: ['', [Validators.required, Validators.email]]
    });

    this.stage = 1;

  }

  ngOnInit() { }

Question

What should I move from the component's constructor to the ngOnInit method?

What kind of code should I place on ngOnInit that cannot / should not be on the constructor?

over 4 years ago · Santiago Trujillo
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!