ngx-pagination - 将分页重置为第一页

ngx-pagination - Reset pagination to first page

我正在使用带有服务器端分页的 ngx-pagination。因此,用户输入一些搜索条件并点击搜索按钮。这会导致为结果的第一页调用服务器。在客户端,我有这段代码来显示分页控件

<div class="col-sm-4">
  <pagination-controls (pageChange)="getPage($event)" 
                       id="serverPaging">
  </pagination-controls>
</div>

<div *ngFor="let result of results | paginate: { 
  id:'serverPaging', 
  itemsPerPage: 10, 
  currentPage: p, 
  totalItems: totalResultCount }">
  ...
</div>

这按预期工作。显示第一页并突出显示分页栏中的“1”。

比方说,用户现在点击了最后一页。这将突出显示分页栏中的最后一页。到目前为止一切正常。

现在用户通过再次单击 'Search' 按钮重新执行搜索。这将重新呈现搜索结果。由于是全新搜索,服务器 returns 第一页。但是,分页栏仍然突出显示最后一页。

如何在某些操作(例如重新执行搜索)中将分页栏重置为第一页。

Angular版本:4.2.4 ngx-分页版本:3.0.0

如果您将 currentPage 属性 与 .ts 文件中的变量绑定,则可以强制更新。
例如:

component.ts

export class DemoComponent implements OnInit {

  public p: number; //Declare the variable that you're using in currentPage

  //Constructor and OnInit...

  onSearch(word: string): void {
    this.SearchService.search(word).subscribe((data: Array<any>) => {
        this.data = data;
        this.p = 1;
    });
  }
}

HTML

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

<div *ngFor="let d of data | paginate: { 
  itemsPerPage: 10, 
  currentPage: p, 
  totalItems: total }"></div>