我需要更改我的表分页器 pageIndex 和 pageSize,当我使用 ViewChild 时,我的代码运行良好,但我想使用信号查询,当我使用信号查询时,我收到此错误;
默认情况下,在
computed
或 effect
中不允许写入信号。
///@ViewChild('paginator') paginator: MatPaginator; -->this works
paginator = viewChild<MatPaginator>('paginator');
_onPaginationChange(event: PageEvent) {
const previousPageIndex = this.req.pageNumber - 1;
const previousPageSize = this.req.pageSize;
this.checkModifiedCellsAndCallback(() => {
this.req.pageNumber = event.pageIndex + 1;
this.req.pageSize = event.pageSize;
this.getTableData();
});
// Revert paginator state if the user cancels the action
if (this.modifiedCells.size > 0) {
setTimeout(() => {
paginator.pageIndex = previousPageIndex;
paginator.pageSize = previousPageSize;
});
}
}
您必须执行 signal 方法才能从
viewChild
访问该元素。
paginator = viewChild<MatPaginator>('paginator');
_onPaginationChange(event: PageEvent) {
const previousPageIndex = this.req.pageNumber - 1;
const previousPageSize = this.req.pageSize;
this.checkModifiedCellsAndCallback(() => {
this.req.pageNumber = event.pageIndex + 1;
this.req.pageSize = event.pageSize;
this.getTableData();
});
// Revert paginator state if the user cancels the action
if (this.modifiedCells.size > 0) {
setTimeout(() => {
const paginator = this.paginator();
paginator.pageIndex = previousPageIndex;
paginator.pageSize = previousPageSize;
});
}
}