简体   繁体   中英

ngx-pagination in Angular 4. How to get page number?

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:

<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:

@Output() pageChange: EventEmitter<number> = new EventEmitter();

And now how to get page when I change it eg when I click on next or Previous?

Have this in the template

<pagination-controls (pageChange)="page = $event"></pagination-controls>

and in the component have a class level variable just denoting the page like page: number = 1; .

UPDATE

you can use this in template (pageChange)="pageChanged($event)"

in component

pageChanged(event){console.log("pageChanged")}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM