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

289
Visualizações
Property 'controls' does not exist on type 'AbstractControl'.ngtsc(2339)

enter image description hereGetting this weird issue in my template please take a look if this can be resolved. I tried some answers related to this but i got nothing.

  ngOnInit(): void {
    this.signUpForm = new FormGroup({
      'userName': new FormControl(null, Validators.required),
      'email': new FormControl(null, [Validators.required, Validators.email]),
      'gender': new FormControl('male'),
      'hobbies': new FormArray([])
    })
  }

  onAddHobby() {
    const control = new FormControl(null, Validators.required);
    (<FormArray>this.signUpForm.get('hobbies')).push(control);
  }
 <div formArrayName="hobbies">
    <h4>your hobbies</h4>
    <button class="btn btn-default" (click)="onAddHobby()">add hobby</button>
    <div
      class="form-group"
      *ngFor="
        let hobbyControl of signUpForm.get('hobbies').controls;
        let i = index
      "
    >
      <input type="text" class="form-control" [formControlName]="i" />
    </div>
  </div>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The simplest way to solve:

let hobbyControl of $any(signUpForm.get('hobbies')).controls;

The compiler is complaining because signUpForm.get('hobbies') returns an abstractControl (which doesn't have controls), but since you know that this is a FormArray you can use $any() https://angular.io/guide/template-expression-operators#any-type-cast-function

about 4 years ago · Juan Pablo Isaza Relatório

0

This is happening because the get() method returns an AbstractControl, which doesn't have the controls property.

To solve it you can add a getter in the class to cast the control to a FormArray

get hobbies(): FormArray {
  return this.signUpForm.get('hobbies') as FormArray;
}

And then use the getter in the template instead as:

<div 
  class="form-group"
  *ngFor="
    let hobbyControl of hobbies.controls;
    let i = index
  "
>

Cheers

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