【发布时间】:2018-06-21 09:42:48
【问题描述】:
我已经安装了一个名为 ngx-pagination 的包。但是我有一个问题,因为当您离开上一页并单击后退按钮时,它会将您重定向到第一页而不是返回上一页?如果我单击浏览器中的后退按钮,如何使其返回上一页?下面是我的代码。
TS
config: any;
constructor() {
this.config = {
currentPage: 1,
itemsPerPage: 2
};
this.route.paramMap
.map(params => params.get('page'))
.subscribe(page => this.config.currentPage = page);
}
}
ngOnInit() {
this.getAllBooks();
}
pageChange(newPage: number) {
this.router.navigate(['/books'], { queryParams: { page: newPage } });
}
getAllBooks() {
this.subscription = this.booksService.getAll()
.subscribe(
(data:any) => {
this.books = data;
console.log(data);
},
error => {
console.log(error);
});
}
HTML
<tbody>
<tr *ngFor="let book of books | paginate: { itemsPerPage: config.itemsPerPage, currentPage: config.currentPage }">
<td>{{ book.SKU }}</td>
<td>{{ book.name }}</td>
<td>{{ book.description }}</td>
</tr>
</tbody>
</table>
<pagination-controls (pageChange)=“pageChange($event)” class="my-pagination"></pagination-controls>
【问题讨论】:
标签: angular parameters pagination angular2-services angular-services