我正在尝试填充 ng-grid,使用和 ngResource $resource 调用,但在 ng-grid 已经呈现之后,ajax 调用似乎总是为时已晚。网格呈现标题但未填充数据。这是代码片段和 jsfiddle
angular.module('api', [ 'ngResource' ]).factory("SERVICE", function($resource) {
return $resource('/api/...', {}, {
query : {
method : 'GET',
isArray : true,
transformResponse : function(data, headers) {
var responsedata = [], data = angular.fromJson(data);
angular.forEach(data.el, function(item, idx) {
//do something to data and add it to responsedata
responsedata.push({"a": item.a});
});
return responsedata;
}
}
});
});
var app = angular.module('myModule', [ 'ngResource', 'api', 'ngGrid' ]);
app.controller('GridController', [ '$scope', 'SERVICE', function($scope, svc) {
$scope.myData = svc.query();
$scope.gridOptions = {
data : myData,
columnDefs : [{
field : "a",
displayName : "a"
}]
};
} ]);
<!-- the html-->
<div class="gridStyle" ng-grid="gridOptions" ng-controller="GridController"></div>