我对这个实现中使用的 Observables 有疑问。我是 Observables 的新手。我正在使用用户列表对现有组件实施 ngx-pagination。问题是下一页没有填充结果(只有第 1 页有 10 个第一个结果),但是正在调用 API,我可以在“网络”选项卡中看到结果。我认为这与 Observables 有关。任何帮助将不胜感激。
零件
pageSize: any;
pageNumber = 1;
count = 0;
ngOnInit() {
this.users$ = this.userapiService.getUsers(this.pageNumber);
}
handlePageChange(event) {
this.pageNumber = event;
this.users$ = this.userapiService.getUsers(this.pageNumber);
}
html
<tr *ngFor="let user of users$.getValue() | paginate: { itemsPerPage: pageSize, currentPage: pageNumber }">
<pagination-controls
(pageChange)="handlePageChange($event)"
previousLabel="Previous"
nextLabel="Next"
></pagination-controls>
服务
getUsers(pageNumber: number): Observable<User[]> {
let params = new HttpParams();
params = params.append('id', id).append('pageNumber', (pageNumber - 1).toString())
.append('pageSize', constants.pageSize);
this.httpService.httpGet(this.Endpoint, params)
.subscribe(
(response: User[]) => {
this.users$.next(response
.filter(user => user
));
});
return this.users$;
}