【问题标题】:ngGrid not displayed when used with route provider与路由提供程序一起使用时不显示 ngGrid
【发布时间】:2013-09-11 23:06:44
【问题描述】:

下面是我的 HTML 代码和执行 Web 服务调用并在 ngGrid 中显示数据的代码。问题在于路由提供程序,我无法在单独的视图中显示网格,但是如果我在没有路由提供程序的情况下执行完全相同的代码,并且只加载该页面,它就可以正常工作。

由于我对 angularJS 很陌生,任何建议都将不胜感激。我做了很多研究,但没有奏效,至少对我而言。如果我在某处错过了相关帖子,请考虑这一点。提前谢谢!

 <div>
    <!--Placeholder for views-->
    <div ng-view=""></div>
</div>

//this is what I have in one of my view for grid.
<div class="gridStyle" data-ng-grid="gridOptions">
</div>

/* display/get/call the JSON data from the web service and bind it to the view */
var app = angular.module('salesApp',['ngGrid']);

app.config (['$routeProvider', function ($routeProvider){
    $routeProvider
            .when('/sales',
            {
                controller:'salesCtrl',
                templateUrl:'Partials/sales.html'

            })
            .when('/associate',
            {
                controller:'assocCtrl',
                templateUrl:'Partials/associate.html'
            })
            .otherwise({redirectTo:'/sales'});
}]);

app.controller('salesCtrl', function($scope, $http) {
    $http.jsonp('http://some url...')
            .success(function (data) {
                $scope.sales = data;

            });

    $scope.gridOptions = {data: 'sales',
        columnDefs:[{field:'Region_Num', displayName: 'Region Num'}
            ],
        showGroupPanel: true
    };

});

【问题讨论】:

    标签: angularjs controller angularjs-routing ng-grid


    【解决方案1】:

    这是一篇较早的帖子;但我遇到了同样的问题。事实证明,当我定义了应用程序/模块时;我没有将 ngGrid 作为选项之一传入:

    myApp = angular.module('myApp', ['ngGrid']);
    

    这显然不是你的问题;正如我在您的代码中看到的那样;所以这个答案可能适用于通过谷歌找到这个问题的其他人。

    【讨论】:

    • 你是对的,你确实必须通过 ngGrid,但我不明白,为什么每当我尝试将它与路由提供程序一起使用时它根本不起作用。
    猜你喜欢
    • 2014-04-10
    • 2016-05-17
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 2020-09-13
    相关资源
    最近更新 更多