admin管理员组文章数量:1317572
I'm trying to create a table using angularjs ui-grid but I keep getting told that $scope.uiGrid is undefined, can anyone tell me what I'm doing wrong?
requestYelp.success(
function(obj)
{
console.log(obj.businesses[0].name);
$scope.gridOptions = {
enableSorting: true,
rowHeight:100,
columnDefs: [
{ field: 'name' },
{ field: 'pany' },
{ field: 'image', cellTemplate:"<img width=\"50px\" ng-src=\"{{grid.getCellValue(row, col)}}\" lazy-src>"}
],
data:[
{name:obj.businesses[0].name,pany: "Company1", image: obj.businesses[0].image_url},
{name:obj.businesses[1].name,pany:"Company2",image:obj.businesses[1].image_url},
{name:obj.businesses[2].name,pany:"Company3",image:obj.businesses[2].image_url}
]
};
}
);
}]);
console.log(obj.businesses[0].name)
will put the right data to the console so it's not a problem with the obj variable. The code only breaks when it gets to gridOptions.
I'm trying to create a table using angularjs ui-grid but I keep getting told that $scope.uiGrid is undefined, can anyone tell me what I'm doing wrong?
requestYelp.success(
function(obj)
{
console.log(obj.businesses[0].name);
$scope.gridOptions = {
enableSorting: true,
rowHeight:100,
columnDefs: [
{ field: 'name' },
{ field: 'pany' },
{ field: 'image', cellTemplate:"<img width=\"50px\" ng-src=\"{{grid.getCellValue(row, col)}}\" lazy-src>"}
],
data:[
{name:obj.businesses[0].name,pany: "Company1", image: obj.businesses[0].image_url},
{name:obj.businesses[1].name,pany:"Company2",image:obj.businesses[1].image_url},
{name:obj.businesses[2].name,pany:"Company3",image:obj.businesses[2].image_url}
]
};
}
);
}]);
console.log(obj.businesses[0].name)
will put the right data to the console so it's not a problem with the obj variable. The code only breaks when it gets to gridOptions.
- The rest of the code, if needed – accasio Commented Jan 16, 2016 at 20:45
2 Answers
Reset to default 6I don't know the exact details how the ui-grid works. But I'm guessing that the ui-grid directive immediately expects $scope.gridOptions
to be available on the $scope
. However, you are assigning $scope.gridOptions
only after the asynchronous http request has finished loading.
You should try to provide an empty (or adequately primed) $scope.gridOptions
immediately before doing the http request.
Alternatively there's a trick to delay linking of any directive by adding an additional ng-if
on the same element. Set it up something like this:
ng-if='whenHttpRequestHasFinishedLoading'
And inside the success()
function just set $scope.whenHttpRequestHasFinishedLoading = true
I know this doesn't answer the OP's question, but this is the first hit from Google, when you search for "ui-grid $scope.uiGrid undefined".
I felt like a plete idiot when I figured out what I'd missed, but in case anyone else runs into the same issue, make sure your ui-grid directive value...
<div ui-grid="gridOptions"></div>
...matches the name of your options object:
$scope.gridOptions = {};
本文标签: javascriptscopeuiGrid is undefinedStack Overflow
版权声明:本文标题:javascript - $scope.uiGrid is undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742005026a2411781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论