在Angular Material上为mat-table添加页脚时,出现此错误:
column.footerCell未定义
下面是我的代码:
<table mat-table [dataSource]="people" class="mat-elevation-z8">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let element">
<strong>{{ element.name }}</strong>
</td>
<td mat-footer-cell *matFooterCellDef> {{ people.length }} people</td>
</ng-container>
...
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-footer-row *matFooterRowDef="displayedColumns"></tr>
</table>
数据如下:
public displayedColumns = ['name'];
public people = [
{id: 1, name: 'John'},
{id: 2, name: 'Jane'},
{id: 3, name: 'Joe'},
];
如果删除页脚代码,则一切正常。 有什么想法吗?
答案 0 :(得分:0)
您必须在其他ng容器中缺少此代码部分
<ng-container>
...
<td mat-footer-cell *matFooterCellDef></td>
</ng-container>
即使您不喜欢某些页脚列中的任何数据或信息,也必须包含此指令