![](/img/trans.png)
[英]How to set angular pageIndex default as 1 in angular material?
[英]subscribe on PageSize and PageIndex of matTable in Angular material
我正在使用 angular 材料表和分页器。 我想将 pageSize 和 pageIndex 发送到 BE,这样我就可以从 BE 进行分页,因为我们有大量数据,而这在 FE 中是不可能的。 如何订阅 pageSize 更改和 PageIndex 更改并获取用户选择的数字以发送给 BE。
您可以按如下方式订阅寻呼机:
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
],
})
export class ListComponent implements AfterViewInit {
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
data: MatTableDataSource<any>;
constructor(private http: HttpClient) {}
ngAfterViewInit(): void {
this.data = new MatTableDataSource([]);
this.data.paginator = this.paginator;
this.paginator.pageIndex = 0;
this.paginator.page.pipe(
startWith({}),
switchMap(() => {
const page = this.paginator.pageIndex + 1;
const itemsPerPage = this.paginator.pageSize;
return this.http.get(`api_url?page=${page}&itemsPerPage=${itemsPerPage}`);
}),
map((apiResponseData) => { return apiResponseData;}),
).subscribe((data) => {
this.data= new MatTableDataSource(data);
this.data._updateChangeSubscription();
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.