【发布时间】:2020-05-27 07:22:14
【问题描述】:
我正在尝试在 Angular 6 中为我的 mat-table 添加分页。我正在使用下面链接中的一些示例。但它不起作用:
https://material.angular.io/components/table/examples
看起来 mat-table 正确地填充了数据,并且分页器正确地显示在其下方,但它们无法连接在一起:
如您所见,分页器设置为每页5条记录,但表中当前页的记录多于记录。它还表示 0 out of 0,这进一步表明链接到表失败。
这是我的 html:
<mat-table #table [dataSource]="dataSource" class="animate topMatDataTable”>
…
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" [pageSize]="5" showFirstLastButtons></mat-paginator>
这是我的 ts 代码:
export class DynamicDataListComponent implements OnInit {
…
dataSource : MatTableDataSource<any>;
…
@ViewChild(MatPaginator) paginator : MatPaginator;
…
ngOnInit() {
…
this.loadEndpoints();
}
async loadEndpoints() {
…
const endpointListObs = await this._dataStorageService.getAPIEndpointList();
endpointListObs.subscribe((endpointList: any[]) => {
this.dataSource = new MatTableDataSource<any>(endpointList);
this.dataSource.paginator = this.paginator;
…
});
…
}
…
}
谁能告诉我我做错了什么?
谢谢。
【问题讨论】:
标签: angular pagination angular-material mat-table