Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng-grid Cannot set property 'gridDim' of undefined

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;
    });

};
like image 450
redrom Avatar asked Jun 06 '14 12:06

redrom


1 Answers

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.

like image 169
Brocco Avatar answered Oct 23 '22 09:10

Brocco