我正在使用 Angular Material 来渲染表格。
代码:
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> Workout type </th>
<td mat-cell *matCellDef="let workout"> {{workout.type}} </td>
</ng-container>
<ng-container matColumnDef="set1">
<th mat-header-cell *matHeaderCellDef> Weight x Reps </th>
<td mat-cell *matCellDef="let workoutData"> {{workoutData.workoutSessions[0].sets[0].weight}} x {{workoutData.workoutSessions[0].sets[0].repetitions}} </td>
</ng-container>
<ng-container matColumnDef="set2">
<th mat-header-cell *matHeaderCellDef> Weight x Reps </th>
<td mat-cell *matCellDef="let workoutData"> {{workoutData.workoutSessions[0].sets[1].weight}} x {{workoutData.workoutSessions[0].sets[1].repetitions}} </td>
</ng-container>
<ng-container matColumnDef="set3">
<th mat-header-cell *matHeaderCellDef> Weight x Reps </th>
<td mat-cell *matCellDef="let workoutData"> {{workoutData.workoutSessions[0].sets[2].weight}} x {{workoutData.workoutSessions[0].sets[2].repetitions}} </td>
</ng-container>
<ng-container matColumnDef="set4">
<th mat-header-cell *matHeaderCellDef> Weight x Reps </th>
<td mat-cell *matCellDef="let workoutData"> {{workoutData.workoutSessions[0].sets[3].weight}} x {{workoutData.workoutSessions[0].sets[3].repetitions}} </td>
</ng-container>
<ng-container matColumnDef="set5">
<th mat-header-cell *matHeaderCellDef> Weight x Reps </th>
<td mat-cell *matCellDef="let workoutData"> {{workoutData.workoutSessions[0].sets[4].weight}} x {{workoutData.workoutSessions[0].sets[4].repetitions}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="workoutTableColumns"></tr>
<tr mat-row *matRowDef="let row; columns: workoutTableColumns;"></tr>
我对此有两个问题:
1) 在这种情况下是否可以使用 *ngFor 遍历数组?现在我的代码看起来太乱了,想清理它。
2)可以使用colspan吗?我没有找到任何解决此问题的信息(问题:https ://github.com/angular/material2/issues/5888 )。
所以,主要问题是:在这种特殊情况下使用 Angular 材质表还是常规材质表更好?