在我的AngularJS应用中,我使用ui-router进行导航,并使用ng-grid显示数据。在我从包含网格的状态过渡到其他任何状态之前,一切工作正常。这是相应的模板:

<div ng-controller="MainUserController" class="container-fluid">
    <div class="row">
        <div class="col-xs-3">
            <div class="gridStyle" ng-grid="gridOptions"></div>
        </div>
    </div>
</div>


从此状态过渡到任何其他状态时,我记录以下错误流:

TypeError: Cannot read property 'off' of null
at HTMLDivElement.<anonymous> (http://127.0.0.1:9000/bower_components/ng-grid/build/ng-grid.debug.js:1008:31)
at HTMLDivElement.jQuery.event.dispatch (http://127.0.0.1:9000/bower_components/jquery/dist/jquery.js:4624:9)
at HTMLDivElement.elemData.handle (http://127.0.0.1:9000/bower_components/jquery/dist/jquery.js:4292:46)
at Object.jQuery.event.trigger (http://127.0.0.1:9000/bower_components/jquery/dist/jquery.js:4533:12)
at jQuery.fn.extend.triggerHandler (http://127.0.0.1:9000/bower_components/jquery/dist/jquery.js:5241:24)
at removePatch [as remove] (http://127.0.0.1:9000/bower_components/angular/angular.js:2213:21)
at Object.leave (http://127.0.0.1:9000/bower_components/angular/angular.js:4079:17)
at Object.leave (http://127.0.0.1:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2668:49)
at cleanupLastView (http://127.0.0.1:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2717:22)
at http://127.0.0.1:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2739:13


删除ng-grid =“ gridOptions”解决了问题,因此为什么我假设ui-router和ng-grid之间发生冲突。

有什么见解吗?

编辑:这就是我声明gridOptions的方式。

        $scope.gridOptions = {
        data: 'data',
        plugins: [new ngGridFlexibleHeightPlugin()],
        showSelectionCheckbox: true,
        columnDefs: [{ field: 'username', displayName: 'Name', width: "**" },
            { field: 'email', displayName: 'Email', width: "**"}]
    };

最佳答案

关于ng-grid和ui-router的冲突,有一个打开的issue这个错误,看来Herve Prot找到了修复,我还没有测试过。

build / ng-grid.js中的952行:

   grid.$topPanel.on('$destroy', function() {
           if(grid.$topPanel == null) // FIX ui-router
            return;

                grid.$topPanel.off('mousedown');

                if (grid.config.enableColumnReordering) {
                    grid.$topPanel.off('drop');
                }

                grid.$topPanel = null;
            });

关于javascript - 从包含ng-grid对象的状态过渡无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23278894/

10-11 22:11
查看更多