MyInternships.in

Forms & Validation

Angular FormArray Dynamic Forms

FormArray holds a list of controls or groups whose length changes at runtime — adding education rows, skills, or work-experience entries. You push and remove entries programmatically and iterate them in the template.


What is FormArray Dynamic Forms in Angular?

FormArray holds a list of controls or groups whose length changes at runtime — adding education rows, skills, or work-experience entries. You push and remove entries programmatically and iterate them in the template.

FormArray Dynamic Forms example

A dynamic skills list
TypeScript
form = this.fb.group({
  name: [''],
  skills: this.fb.array([this.fb.control('', Validators.required)]),
});

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

addSkill(): void {
  this.skills.push(this.fb.control('', Validators.required));
}

removeSkill(i: number): void {
  this.skills.removeAt(i);
}

Rendering it

HTML
<div formArrayName="skills">
  @for (ctrl of skills.controls; track $index) {
    <input [formControlName]="$index">
    <button type="button" (click)="removeSkill($index)">Remove</button>
  }
</div>
<button type="button" (click)="addSkill()">Add skill</button>

Key points to remember

  • A getter cast to FormArray keeps the template readable and typed.
  • Use formArrayName on the container and the numeric index as formControlName.
  • For groups rather than single controls, use [formGroupName]="$index".

Common mistakes with FormArray Dynamic Forms

  • Forgetting the formArrayName wrapper, so the indexed controls do not bind.
  • Tracking by value in @for, which breaks when two entries hold the same text.

Angular FormArray Dynamic Forms— Interview Questions & FAQs

When should I use FormArray instead of FormGroup?+

FormGroup for a fixed set of named fields; FormArray when the number of controls changes at runtime and they are addressed by position.

Related Angular Topics

Keep learning with these closely related lessons.

Ready to use your Angular skills?

Find verified Angular internships and fresher developer jobs across India.

Browse Angular Internships