javascript - $scope.uiGrid is undefined -


i'm trying create table using angularjs ui-grid keep getting told $scope.uigrid undefined, can tell me i'm doing wrong?

    requestyelp.success(     function(obj)      {         console.log(obj.businesses[0].name);          $scope.gridoptions = {             enablesorting: true,             rowheight:100,             columndefs: [             { field: 'name' },             { field: 'company'  },             { field: 'image', celltemplate:"<img width=\"50px\" ng-src=\"{{grid.getcellvalue(row, col)}}\" lazy-src>"}             ],              data:[             {name:obj.businesses[0].name,company: "company1", image: obj.businesses[0].image_url},             {name:obj.businesses[1].name,company:"company2",image:obj.businesses[1].image_url},             {name:obj.businesses[2].name,company:"company3",image:obj.businesses[2].image_url}             ]         };     } ); }]); 

console.log(obj.businesses[0].name) put right data console it's not problem obj variable. code breaks when gets gridoptions.

i don't know exact details how ui-grid works. i'm guessing ui-grid directive expects $scope.gridoptions available on $scope. however, assigning $scope.gridoptions after asynchronous http request has finished loading.

you should try provide empty (or adequately primed) $scope.gridoptions before doing http request.

alternatively there's trick delay linking of any directive adding additional ng-if on same element. set this:

ng-if='whenhttprequesthasfinishedloading'

and inside success() function set $scope.whenhttprequesthasfinishedloading = true


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -