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

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