最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ng-grid Cannot set property 'gridDim' of undefined - Stack Overflow

programmeradmin1浏览0评论

I'm new in Angular, and I try to declare gridOption for ng-grid Within a function in costroller.

It cause an error:

TypeError: Cannot set property 'gridDim' of undefined

I tried to solve it using $scope.apply and ng-if in template. But nothing from this is working for me.

Thanks for any advice:

method of the Controller:

$scope.getTest = function() {

    $http.get('.svc/getAllCustomers')
    .success(function (data, status, headers, config) {
            //$scope.myData = data;
            console.log('Sucess' + data);
            // definition for ng-grid table 
            $scope.myData = [{ name: "Moroni", age: 50 },
                             { name: "Tiancum", age: 43 },
                             { name: "Jacob", age: 27 },
                             { name: "Nephi", age: 29 },
                             { name: "Enos", age: 34}];
            $scope.gridOptions = { data: 'myData' };
            //$scope.$apply();
    })
    .error(function(data, status, headers, config) {
            $scope.myData = data;
    });

};

I'm new in Angular, and I try to declare gridOption for ng-grid Within a function in costroller.

It cause an error:

TypeError: Cannot set property 'gridDim' of undefined

I tried to solve it using $scope.apply and ng-if in template. But nothing from this is working for me.

Thanks for any advice:

method of the Controller:

$scope.getTest = function() {

    $http.get('http://www.iNorthwind.com/Service1.svc/getAllCustomers')
    .success(function (data, status, headers, config) {
            //$scope.myData = data;
            console.log('Sucess' + data);
            // definition for ng-grid table 
            $scope.myData = [{ name: "Moroni", age: 50 },
                             { name: "Tiancum", age: 43 },
                             { name: "Jacob", age: 27 },
                             { name: "Nephi", age: 29 },
                             { name: "Enos", age: 34}];
            $scope.gridOptions = { data: 'myData' };
            //$scope.$apply();
    })
    .error(function(data, status, headers, config) {
            $scope.myData = data;
    });

};
Share Improve this question asked Jun 6, 2014 at 12:55 redromredrom 11.6k33 gold badges165 silver badges268 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 19

I just ran into this issue yesterday....

In order to initially render, ng-grid needs the options to be supplied initially, not after your $http promise is resolved.

Move your $scope.gridOptions = { data: 'myData' } call outside of your success promise and your issue should go away.

It is working for me when we define 'gridOptions' outside of success and error methods as shown below:

$scope.getCategory = function(){
            var listURL = "/sites/AwardTrackingSystem/_api/web/lists/getByTitle('Categories')/items"+
                        "?$select=Id,Title";                                        
                        srvcQuerySPList.getItems(listURL)
            .then(
                function(data){
                                $scope.allCategory = data;
                              },
                function(data){alert('Error Awards---------------'+JSON.stringify(data));}

            );

        };
        $scope.gridOptions = { data: 'allCategory'};
发布评论

评论列表(0)

  1. 暂无评论