我不知道为什么在我将页面从 1 更改为 2 后 bookParams 中的 pageNumber 会自动重置为 1。
export class BookListComponent implements OnInit {
books: Book[];
bookParams: BookParams;
pagination: Pagination;
constructor(private bookService: BookService, private accountService: AccountService) {
accountService.currentUser$.pipe(take(1)).subscribe(user => {
this.bookParams = new BookParams(user);
console.log("contructor " + this.bookParams.pageNumber);
})
}
ngOnInit(): void {
let a = this.bookParams;
this.loadBooks();
}
loadBooks() {
console.log("loadBooks" + this.bookParams.pageNumber);
this.bookService.getBooks(this.bookParams).subscribe(response => {
this.books = response.result;
this.pagination = response.pagination;
this.pagination.currentPage = 1;
})
}
pageChanged(event: any) {
console.log("PageChange "+event.page);
this.bookParams.pageNumber = event.page;
this.loadBooks();
}
}
BookParams.ts
export class BookParams {
pageSize = 8;
pageNumber = 1;
}
点击更改页面后的图片