typescript Angular 4 中的 ngx-pagination. 如何获取页码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45903255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ngx-pagination in Angular 4. How to get page number?
提问by Mateusz Sobczak
I using Angular 4 and Typescript with library ngx-pagination. I a bit don't understand this library. I have paggination in Java and I want to send page number when page is changed. Numbers of all items came from Java site. I don't know how to handle this problem. I created this code: In html:
我将 Angular 4 和 Typescript 与库 ngx-pagination 一起使用。我有点不明白这个库。我在 Java 中有分页,我想在页面更改时发送页码。所有项目的数量来自 Java 站点。我不知道如何处理这个问题。我创建了这个代码:在 html 中:
<tr *ngFor="let story of stories | paginate: { itemsPerPage: this.size, currentPage: this.page, totalItems: this.numberOfElements }" style="text-align: left; word-break: break-all;">
<pagination-controls (pageChange)="pageChange.emit($event)"></pagination-controls>
and in TS I created this:
在 TS 中我创建了这个:
@Output() pageChange: EventEmitter<number> = new EventEmitter();
And now how to get page when I change it e.g. when I click on next or Previous?
现在如何在我更改页面时获取页面,例如当我单击下一个或上一个时?
回答by Rahul Singh
Have this in the template
在模板中有这个
<pagination-controls (pageChange)="page = $event"></pagination-controls>
and in the componenthave a class level variable just denoting the page like page: number = 1;
.
并且在组件中有一个类级别的变量,只是表示像 page: number = 1;
.
UPDATE
更新
you can use this in template(pageChange)="pageChanged($event)"
你可以在模板中使用它(pageChange)="pageChanged($event)"
in component
在组件中
pageChanged(event){console.log("pageChanged")}