Angular Material v6 Mat-Footer - “Cannot read property 'template' of undefined”

≯℡__Kan透↙ 提交于 2020-01-01 09:32:56

问题


I'm trying to implement a footer row into a mat-table component after recently upgrading to angular 6 for this purpose, but after adding both the mat-footer-cell and mat-footer-row elements in the table, I get the following error:

ERROR TypeError: Cannot read property 'template' of undefined at MatFooterRowDef.push../node_modules/@angular/cdk/esm5/table.es5.js.CdkFooterRowDef.extractCellTemplate (vendor.js:17400)

The table still appears on the page, but with no data, no footer row, and a T symbol where to the right of each column heading.

HTML:

  <ng-container matColumnDef="total">

    <mat-header-cell *matHeaderCellDef mat-sort-header style="width: 15%; flex: none">Total</mat-header-cell>

    <mat-cell *matCellDef="let item" style="width: 15%; flex: none">{{item.total | currency: 'GBP'}}</mat-cell>

    <td mat-footer-cell *matFooterCellDef>100</td>

  </ng-container>

  <mat-header-row *matHeaderRowDef="tableColumns"></mat-header-row>

  <mat-row *matRowDef="let row; columns: tableColumns" (click)="editItem(row)"></mat-row>

  <tr mat-footer-row *matFooterRowDef="tableColumns"></tr>

</mat-table>

回答1:


FIXED: This was not made clear in the material documentation, but all columns must contain a <mat-footer-cell/> element, even if only one column will contain content.




回答2:


You can define your own "tableFooterColumns" variable.

tableFooterColumns: string[] = ['total'];

and use it in the template (change "colspan" for your needs):

 <tr mat-footer-row *matFooterRowDef="tableFooterColumns" colspan="2"></tr>


来源:https://stackoverflow.com/questions/50641359/angular-material-v6-mat-footer-cannot-read-property-template-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!