javascript - 从包含 ng-grid 对象的状态转换不起作用

标签 javascript angularjs ng-grid angular-ui-router

在我的 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: "**"}]
    };

最佳答案

有一个开放的 issue关于 ng-grid 和 ui-router 冲突的错误,似乎 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/

相关文章:

javascript - 地理位置共享对话框不会在每次页面刷新时显示

javascript - 如果按下了有效字符,如何检查 div 上的 keydown

javascript - 通过 JQuery Onclick 将值传递到函数中

javascript - js 导航栏边框底线和滚动时的颜色变化

angularjs - ngTable.reload() 无法刷新 ng-table 第二次不显示新数据

angularjs - 使用 WebAPI 对 ng-grid 进行服务器端分页+过滤+排序

javascript - AngularJS ng :submit on 'enter' key

arrays - 移动 Firebase 数组中的项目

css - 如何更改 ui-grid 行的高度?

html - ng-grid 数据重叠