将 angularCompileRows 设置为 true 时无法读取 null 的 属性“$apply”
Cannot read property '$apply' of null when set angularCompileRows to true
我使用 AngularJS 1.7 和 ag-grid 18.0.1.
当我将 angularCompileRows 设置为 true 时,控制台出现以下错误:
Uncaught TypeError: Cannot read property '$apply' of null
at eval (rowRenderer.js:586)
这是对应的代码(这是agGrid代码):
RowRenderer.prototype.checkAngularCompile = function () {
var _this = this;
// if we are doing angular compiling, then do digest the scope here
if (this.gridOptionsWrapper.isAngularCompileRows()) {
// we do it in a timeout, in case we are already in an apply
setTimeout(function () {
_this.$scope.$apply();
}, 0);
}
};
这是我的选择:
const gridOptions = {
rowData: null,
columnDefs: [...],
enableColResize: true,
onColumnResized: (params) => {
angularCompileRows: true,
suppressCellSelection: true,
enableSorting: true,
enableServerSideSorting: true,
rowModelType: 'infinite',
pagination: true,
paginationPageSize: 10,
unSortIcon: true,
suppressPaginationPanel: true,
suppressHorizontalScroll: true,
onGridReady: (params) => {
const dataSource = {
rowCount: null, // behave as infinite scroll
getRows: (rowsParams) => {
// call my API then rowsParams.successCallback(data, isLastPage);
},
};
gridOptions.api.setDatasource(dataSource);
},
};
调用栈
以及调试选项的输出
正在渲染网格:headers 没问题,但内容是空的。
Plunker https://plnkr.co/edit/j5ubZWit4CO5zmldgqnl?p=preview based on this exemple https://www.ag-grid.com/javascript-grid-infinite-scrolling/#example-2-equal-pagination-page-size-and-large-infinite-block-si 并将 angularCompileRows: true
添加到选项
编辑: 这是一个有 angular 应用程序的傻瓜 https://plnkr.co/edit/7eOKSXbcCzLdYWtPygrS?p=preview
错误未触发,但 angularCompileRows 似乎未被调用
如果您打算将 angular 与网格一起使用,为什么不先加载 angular :)。您没有加载 angular 并且您没有在网格中使用任何 angular 代码,没有它怎么调用 $scope.$apply()
?
使 angularCompileRows = false
和您的网格工作。如果您要使用 angular,请从 angular 示例开始。
我使用 AngularJS 1.7 和 ag-grid 18.0.1.
当我将 angularCompileRows 设置为 true 时,控制台出现以下错误:
Uncaught TypeError: Cannot read property '$apply' of null
at eval (rowRenderer.js:586)
这是对应的代码(这是agGrid代码):
RowRenderer.prototype.checkAngularCompile = function () {
var _this = this;
// if we are doing angular compiling, then do digest the scope here
if (this.gridOptionsWrapper.isAngularCompileRows()) {
// we do it in a timeout, in case we are already in an apply
setTimeout(function () {
_this.$scope.$apply();
}, 0);
}
};
这是我的选择:
const gridOptions = {
rowData: null,
columnDefs: [...],
enableColResize: true,
onColumnResized: (params) => {
angularCompileRows: true,
suppressCellSelection: true,
enableSorting: true,
enableServerSideSorting: true,
rowModelType: 'infinite',
pagination: true,
paginationPageSize: 10,
unSortIcon: true,
suppressPaginationPanel: true,
suppressHorizontalScroll: true,
onGridReady: (params) => {
const dataSource = {
rowCount: null, // behave as infinite scroll
getRows: (rowsParams) => {
// call my API then rowsParams.successCallback(data, isLastPage);
},
};
gridOptions.api.setDatasource(dataSource);
},
};
调用栈
以及调试选项的输出
正在渲染网格:headers 没问题,但内容是空的。
Plunker https://plnkr.co/edit/j5ubZWit4CO5zmldgqnl?p=preview based on this exemple https://www.ag-grid.com/javascript-grid-infinite-scrolling/#example-2-equal-pagination-page-size-and-large-infinite-block-si 并将 angularCompileRows: true
添加到选项
编辑: 这是一个有 angular 应用程序的傻瓜 https://plnkr.co/edit/7eOKSXbcCzLdYWtPygrS?p=preview
错误未触发,但 angularCompileRows 似乎未被调用
如果您打算将 angular 与网格一起使用,为什么不先加载 angular :)。您没有加载 angular 并且您没有在网格中使用任何 angular 代码,没有它怎么调用 $scope.$apply()
?
使 angularCompileRows = false
和您的网格工作。如果您要使用 angular,请从 angular 示例开始。