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

363
Vistas
Angular (Cannot read properties of null (reading 'addControl') - Change form value in child component

I want to update the form value from the child component. Here is the parent component:

app.component.ts

ngOnInit() {
  this.form = this.fb.group({
     priority: [this.editPriority, Validators.nullValidator],
     . 
     .
     .
  });
 }

app.component.html

  <div *ngIf="editType === 'priority'">
    <app-child[form]="form"></app-child>
  </div>

child.component.ts:

export class ChildComponent implements OnInit {
  @Input() form: FormGroup;
  constructor() { }

  ngOnInit(): void {
  }

}

child.component.html:

  <div class="col-sm-2">
    <label for="priority"> Priority</label>
  </div>
  <div class="input-group col-sm-10">
    <input type="text" class="form-control" id="priority" name="priority" formControlName="priority"
           placeholder="priority">
  </div>

I tried like this stackBlitz but I got the below error:

TypeError: Cannot read properties of null (reading 'addControl')

I tried adding:

this.form.addControl('priority', new FormControl());

inside ngOnInitbut still I got the error.

Any suggestions for updating data through the child component?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Farzan. I use Angular event emitters, where the child calls a function in the parent (or vice-versa) when needed. This function exists in the parent or child and is called when needed, including the ability to pass parameters. Not sure if it works for your situation, but I know it works quite well for me very often.

Here is a simple example: Pass Event from child component to parent component Angular 5

about 4 years ago · Juan Pablo Isaza 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