formControlName="personLabel" formControlName="personValue" . , persons .
FormControl :
this.personControl = new FormGroup({
personLabel0 : new FormControl('',
[
Validators.required
]),
personValue0 : new FormControl('',
[
Validators.required
]),
personLabel1 : new FormControl('',
[
Validators.required
]),
personValue1 : new FormControl('',
[
Validators.required
]),
personLabel2 : new FormControl('',
[
Validators.required
]),
personValue2 : new FormControl('',
[
Validators.required
])
});
formControlName :
public getName(word, i) {
return "person" + word + i;
}
:
<div *ngFor="let p of persons; let i = index">
index : {{i}}<br/>
label : {{p.label}}<br/>
value : {{p.value}}<br/>
<input type="text"
maxlength="30"
[id]="'label-'+p.id"
[(ngModel)]="p.label"
formControlName="{{getName('Label', i)}}"
placeholder="{{p.id}}"/>
<input type="text"
maxlength="30"
[id]="'value-'+p.id"
[(ngModel)]="p.value"
formControlName="{{getName('Value', i)}}"/>
</div>
FormGroup, , FormControls FormGroup (personControl), . , .
Plunker: https://plnkr.co/edit/ERWA6GKX9VYADouPb6Z2?p=preview