材料表中的Angular 6索引不起作用

时间:2018-12-15 10:58:25

标签: html angular indexing angular-material

向表行添加索引时出现问题。 我已经分配了这样的索引值:

<ng-container matColumnDef="id">
  <mat-header-cell *matHeaderCellDef>#</mat-header-cell>
  <mat-cell *matCellDef="let i = index"> {{i+1}} </mat-cell>
</ng-container>

此解决方案在一个表上运行,但在第二个表上返回NaN。有谁知道如何解决这个问题?

在第二张表上,我正在使用可扩展行,因此添加了multiTemplateDataRows属性。其他一切都一样。我正在使用Material Design v7.11

1 个答案:

答案 0 :(得分:1)

使用multiTemplateDataRows属性时,不能使用索引。相反,您必须使用dataIndex或renderIndex。

<mat-cell *matCellDef="let i = renderIndex;">{{i+1}}</mat-cell>
相关问题