how to define index in angular material table

Can you add index to let element; let i = index;" as you'd do with *ngFor?

<mat-row *matRowDef="let row; columns: displayedColumns; let i = index"></mat-row>

Or like so:

<ng-container matColumnDef="index">
  <mat-header-cell *matHeaderCellDef> Index </mat-header-cell>
  <mat-cell *matCellDef="let element; let i = index;">{{i}}</mat-cell>
</ng-container>

Working Example: https://stackblitz.com/edit/angular-acdxje?file=app/table-basic-example.html


For anyone who has set the multiTemplateDataRows property of mat-table to true, you can't use index. Instead you have use either dataIndex or renderIndex.

<mat-cell *matCellDef="let row; let i = dataIndex;">{{i}}</mat-cell>

See https://github.com/angular/material2/issues/12793