文章内容

2020/8/27 14:55:14,作 者: 黄兵

Material Angular Paginator 翻页事件

最近在使用Material Angular Paginator组件,按照官方示例,如何获取翻页事件,代码如下:

<mat-paginator [length]="length"
[pageSize]="pageSize"
[pageSizeOptions]="pageSizeOptions"
(page)="pageEvent = getNotices($event)">
</mat-paginator>

notices.component.ts:

// MatPaginator Inputs
length: number;
pageSize = 10;
pageSizeOptions: number[] = [5, 10, 25, 100];

// MatPaginator Output
pageEvent: PageEvent;
getNotices($event: PageEvent): any {
// 点击paginator事件,获取pageIndex,重新加载页面
this.pageIndex = $event.pageIndex;
this.pageSize = $event.pageSize;
this.notices();
}
notices() {
this.sub = this._noticeService.getNotice(this.pageIndex, this.pageSize).subscribe(res => {
this.result = res.notices;
this.showMore = res.count > 10;
this.length = res.count;
}, (error: any) => {
this.errorMessages.push({description: 'Server error. Try later.'});
this.childError.emit(this.errorMessages);
this._logService.error(error, `path: ${this.path}`, 'function: notices()');
});
}

这里Paginator组件通过调用getNotices()实现了翻页的一些操作,主要是后端获取数据。


参考资料:

1、Angular Material paginator

2、How to use paginator from material angular?


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - Material Angular Paginator 翻页事件

分享到:

发表评论

评论列表