首页 文章

将angularCompileRows设置为true时,无法读取null的属性'$apply'

提问于
浏览
7

我使用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);
            },
        };

调用堆栈

enter image description here

和调试选项的输出

enter image description here

网格正在渲染: Headers 可以,但内容为空 .

Plunker https://plnkr.co/edit/j5ubZWit4CO5zmldgqnl?p=preview基于此示例https://www.ag-grid.com/javascript-grid-infinite-scrolling/#example-2-equal-pagination-page-size-and-large-infinite-block-si并将 angularCompileRows: true 添加到选项

EDIT: 这里有一个带角度应用程序的plunker https://plnkr.co/edit/7eOKSXbcCzLdYWtPygrS?p=preview

错误未被触发,但似乎没有调用angularCompileRows

1 回答

  • 2

    如果你没有加载角度并且你没有在网格中使用任何角度代码,那么如果没有它,如何调用 $scope.$apply()

    使 angularCompileRows = false 和你的网格工作 . 如果您要使用角度,请从角度示例开始 .

相关问题