Reactive Forms
- import { FormGroup, FormArray , FormControl, FormBuilder } from '@angular/forms';
FormArray is similar to an array. We can push the new items into it and loop throughout items to append in HTML.
Sometimes, we need to give control creation logic to the end users as per their capabilities and skills or experience.
For example (Degrees)
- Raj – BCA
- Annu – B.Tech, MS
Therefore, we need an additional field as per the qualification and experience. In this demo, I’m creating additional fields for education and other fields by clicking on “Add Other Details”. This is a continuation of my last blog on Angular version 7.
This is a basic form with some fields with "Add Other Details" button. In this below screen, I clicked "Add other details" and it generated the same fields to capture additional details as below.
Let's see the "Add Other Details" ClickEvent.
Step 1
Create a personal details form on initialization.
- ngOnInit() {
- this.personalForm = this.formBuilder.group({
- firstName: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(8)]],
- lastName: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(8)]],
- address: ['', [Validators.required]],
- other: this.formBuilder.array([ this.addOtherSkillFormGroup()])
- });
- }
Step 2
Create a method which returns control objects.
- addOtherSkillFormGroup(): FormGroup {
- return this.formBuilder.group({
- education: ['', Validators.required],
- age : ['', Validators.required],
- degree: ['Bachelor', Validators.required]
- });
- }
Step 3
Here is the button click event code.
- addButtonClick(): void {
- (<FormArray>this.personalForm.get('other')).push(this.addOtherSkillFormGroup());
- }
This code contains the HTML changes to loop a FormArray,

Prabodh BansalPosted Sep 13, 2019, 2:07 AM
Sir i need to talk to you . mu mobile no is 9810795067
Aress IndiaPosted Aug 12, 2019, 2:28 AM
How to remove dynamically added fields? and How to use setValidators to validate dynamic fields conditionally?
Rahul ShuklaPosted Apr 28, 2019, 4:13 AM
How to submit this form with details entry?
Amit Kumar SinghPosted Nov 15, 2018, 12:24 AM
Thanks for Sharing Rajendra !!!