var app = angular.module("finApp", ["ui.grid"]);
app.controller(
"finController",
function($scope, $http) {
$http.get("url", "data")
.then(function(response) {
$scope.gridOptions.data = response.data;
}, function(errorResponse) {});
});

<link href="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ui-grid="gridOptions" class="grid"></div>
&#13;
执行上面的代码时,我遇到错误:
angular.min.js:122 TypeError:无法读取属性&#39;数据&#39;未定义的 at new(ui-grid.js:3330)
在Object.invoke(angular.min.js:43)
在Q.instance(angular.min.js:93)
答案 0 :(得分:0)
在http请求
之前初始化$scope.gridOptions = {}
答案 1 :(得分:0)
试试这个:
来自API的成功响应只是concat
响应数据进入gridData
数组。由于gridData
仅被分配回$scope.gridOptions.data
。
--------
JS file
--------
$scope.gridOptions = {
data: 'gridData',
..........,
..........,
..........
}
$scope.gridData = [];
$scope.gridData = $scope.gridData.concat(response.data);
答案 2 :(得分:0)
按日志或警告检查回复
或定义如下所示的网格列以测试您的网格是否正常工作:
$scope.gridOptions = {
paginationPageSizes: [10, 20, 50],
paginationPageSize: 10,
enableColumnMenus: false,
columnDefs: [
{
width: '10%',
field: 'lastname',
displayName: 'Last Name'
},
{
width: '25%',
field: 'firstname',
displayName: 'First Name'
},
{
width: '8%',
field: 'Status',
displayName: 'Status'
},
{
width: '6%',
field: "actions",
displayName: "Actions",
cellTemplate: '<a href="#" title="test" class="Icon"></a>'
}
]
};
在JS中
var app = angular.module("finApp", ["ui.grid"]);
app.controller(
"finController",
function($scope,$http){
$http.get("url","data")
.then(function(response) {
$scope.gridOptions.data =response.data;
},function(errorResponse) {
});
});
请参阅:UI GRID