Could help me in a doubt, I have a form with an array where FormControl
"id" exists. Is there a way to get the value of index
to fill this field?
<tr *ngFor="let item of invForm.controls.tool.controls; let i= index" [formGroupName]="i" >
<td>
<mat-form-field floatLabel='never'>
<input matInput type="number" style="text-align: right" formControlName="Id" value="{{i+1}}" >
</mat-form-field>
</td>
</tr>
I made this example on stackblitz .
[Resolved]
I solved the problem with trackBy: trackByFn
<tr *ngFor="let item of invForm.controls.tool.controls; let i= index ;trackBy: trackByFn" [formGroupName]="i" >
and no component
,
trackByFn(index, item) {
item.value.Id = index+1
return index;
}
I also leave the resolution in the stackblitz