How to get the index value of ngFor

-1

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

    
asked by anonymous 22.01.2018 / 11:40

1 answer

1
<ul>
  <li *ngFor="let item of especialidades; let i = index">
    {{i}} {{item.codigo}}
  </li>
</ul>

Syntax Angle ngFor: link

    
22.01.2018 / 12:26