I followed a tutorial from the website link https://scotch.io/tutorials/how-to-build-nested-model-driven-forms-in-angular-2 , to make a reactive form with an ability to add multiple form controls and that worked well. I moved the nested form controls in a separate component as guided in the tutorial and i need to access the index value of the formarray from the parent component. I want this index value to set that in one of the formconrols default value here is my code in plnkr, http://plnkr.co/edit/ZjEuBWrmJDiRmP4FeCzv?p=preview
my separated day and description component,
import { Component, Input } from '@angular/core';
import { FormArray, Validators, FormGroup } from '@angular/forms';
@Component({
selector: 'day-and-daydescription',
template: ` <div [formGroup]="formGroup">
<div class="form-group col-xs-4" >
<label for="text">Day</label>
<input type="text" class="form-control" formControlName="day" [ngModel]="group.i + 1" readonly>
</div>
<!--Day Description-->
<div class="form-group col-xs-4">
<label>Description</label>
<input type="text" class="form-control" formControlName="description">
</div>
<div>`
})
export class DayAndDescriptionComponent {
@Input('group')
public formGroup: FormGroup;
}
Please have a look at the whole code in plunker.