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

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

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