0

Object is possibly 'null'. Element implicitly has an 'any' type because expression of type '"controls"' can't be used to index type 'AbstractControl<any, any>'.

Property 'controls' does not exist on type 'AbstractControl<any, any>'.

<div class="form-group" formArrayName="skills">
    <ng-container *ngFor="let skill of reactiveForm.get('skills')['controls']; let i = index;">
          <label for="Skills">Skills</label>
          <input type="text">
    </ng-container>
</div>

ts file

reactiveForm!: FormGroup;
ngOnInit(): void {
    this.reactiveForm = new FormGroup({
      // To set default value we need to pass this value instead of null.
      firstname: new FormControl(null, Validators.minLength(4)),
      lastname: new FormControl(null, Validators.required),
      email: new FormControl('[email protected]', [Validators.required, Validators.email]),
      country: new FormControl('Canada'),
      gender: new FormControl('male'),
      hobbies: new FormControl(null),
      skills: new FormArray([
        new FormControl(null),
      ])
    })
  }

  onSubmit() {
    console.log(this.reactiveForm);
  }
}
1
  • You have the same question (with the solution) in this SO. Please, before ask a question try look for if there a similar question yet answered. (the SO it's the question suggested in "related question" Commented Sep 10, 2023 at 10:36

1 Answer 1

0

in ts file write a getter for skills

get skills() {
  return this.reactiveForm.get('skills') as FormArray;
}

and in HTML

<div class="form-group" formArrayName="skills">
  <ng-container *ngFor="let skill of skills.controls; let i = index;">
        <label for="Skills">Skills</label>
        <input type="text">
  </ng-container>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.