我正在使用ngb分页
以下是代码:
<ngb-pagination class='float-right' [maxSize]=10
(pageChange)="currentPage=$event;paginationNavigation('pagination');"
[collectionSize]="totalobjects" [(pageSize)]="pageSize"
[(page)]="currentPage" aria-label="Default pagination">
</ngb-pagination>
我正在从查询参数中获取currentPage值:
const params = this._route.snapshot.queryParams
this.currentPage=parseInt(params['currentPage']) || 1;
但这并没有在刷新/加载页面时设置分页html值,它显示为第一页。
如果你不更改页面,因为ngOnInit不会再次执行而将其放入ngOnInitconst params = this._route.snapshot.queryParams
中,否则你会刷新导航器或在更改页面时(我想说你在/default
中并转到/product-list/2
,但如果你在product-list/1
中并转到product-list/2
,ngOnInit不会再次执行(
您需要订阅ActivatedRoute.queryParams
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.queryParams.subscribe(params => {
this.currentPage = (+params['currentPage']) || 1;
});
}
注意:请确保您已将路线定义为path: 'product-list/:currentPage'