当使用角度材料表时我应该如何定义索引变量,因为该表中未使用 ngFor。
我确实在文档中搜索过它,但在它的任何地方都没有提到索引。
<mat-table #table [dataSource]="dataSource">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Position Column -->
<ng-container matColumnDef="position">
<mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.position}} </mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.name}} </mat-cell>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="weight">
<mat-header-cell *matHeaderCellDef> Weight </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.weight}} </mat-cell>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<mat-header-cell *matHeaderCellDef> Symbol </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.symbol}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
我在哪里以及如何为我在这个表中使用的数组定义一个索引变量,以便我可以在我的表本身中绑定索引值。
原文由 pushplata patel 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以像使用 --- 一样将
index
添加到let element; let i = index;"
*ngFor
吗?或者像这样:
工作示例: https ://stackblitz.com/edit/angular-acdxje?file=app/table-basic-example.html