FormArray extends AbstractControl , so it has a valueChanges property that emits chanes.
this.form = this.fb.group({ providers: this.fb.array([]), }); (this.form.get('providers') as FormArray).push(new FormControl('', Validators.required)); (this.form.get('providers') as FormArray).push(new FormControl('', Validators.required)); (this.form.get('providers') as FormArray).valueChanges.subscribe(values => { console.log(values); });
In your template:
<input *ngFor="let field of form.controls.providers.controls;" [formControl]="field">
values in the subscription will return an array with the value of each input field for any changes (grammatically or from the user interface).
In case FormGroup in FormArray nothing changes. just use the following component code.
(this.form.get('providers') as FormArray).push(this.fb.group({ 'name': '', 'age': '' }));
and the template will be:
<div *ngFor="let field of form.controls.providers.controls;" [formGroup]="field"> <input formControlName="name" placeholder="name"> <input formControlName="age" placeholder="age"> </div>
here plunker
source share