简体   繁体   English

角分页,获取当前页码

[英]Angular Pagination, Get Current Page number

I am trying to get current page in pagination. 我正在尝试获取当前页面的分页。 This the code in app.component.html: 这是app.component.html中的代码:

<ngb-pagination  [collectionSize]="500" [(page)]="page" (click)="showPageIndex(page)" aria-label="Default pagination" ></ngb-pagination>

<p>current page is {{page}}</p>

in app.component.ts: 在app.component.ts中:

public page = 1;


   showPageIndex(pageIndex){
     this.page = pageIndex;
     console.log(this.page);
   }

When I click on the page (say page 12), I am getting the result as '1'. 当我单击页面(例如第12页)时,得到的结果为“ 1”。 When, I click again, I am getting the result as '12' (correct one). 当我再次单击时,得到的结果为“ 12”(正确的结果)。

However, 然而,

current page is {{page}} 当前页面是{{page}}

, is displaying the correct page. ,显示正确的页面。

It seems that when the onclick is triggered, it gets the value of the current page (not the one after the click is done). 似乎在触发onclick时,它将获取当前页面的值(而不是单击完成后的页面)。

Is something wrong with this approach? 这种方法有什么问题吗? Should, I write the code for pagination manually in this case, instead of using a library? 在这种情况下,我应该手动编写用于分页的代码,而不是使用库吗?

Appreciate your support. 感谢您的支持。

Thanks, 谢谢,

尝试使用(pageChange)=“ onPageChange(currentPage)而不是(click)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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