gpt4 book ai didi

Angular 垫表错误 : Missing definitions for header and row

转载 作者:太空狗 更新时间:2023-10-29 17:02:20 26 4
gpt4 key购买 nike

我正在使用 Angular Material 5.2.5 中的 MatTable。我试图用通过服务器请求获得的数据填充表。

用户界面

  <mat-table [dataSource]="dataSource">
<ng-container matColumnDef="number">
<mat-header-cell *matHeaderCellDef>#</mat-header-cell>
<mat-cell *matCellDef="let i = index">{{i + 1}}</mat-cell>
</ng-container>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let user">{{user.userName}}</mat-cell>
</ng-container>
...
</mat-table>

组件代码

  public dataSource = new MatTableDataSource<User>()
public displayedColumns = ['number', 'name', 'email', 'phone', 'joiningDate']

从服务器接收数据时向dataSource添加数据

 onGettingPartnerUsers(userList: User[]) {
console.log('userList', userList)
if (!Util.isFilledArray(userList)) {
// TODO show message no user found
} else {
this.dataSource.data = userList
}
}

我正在获取用户列表。但是会抛出此错误。

Error: Missing definitions for header and row, cannot determine which columns should be rendered.

错在哪里?

PS:我在关注this关于使用 MatTable 的博客

最佳答案

您必须在表格中添加 mat-rowmat-h​​eader-row(可选)标签:

<mat-table>
.... columns definitions

<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

在此处查看更多示例 https://material.angular.io/components/table/overview

关于 Angular 垫表错误 : Missing definitions for header and row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49026943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com