我试图填充一个NG-格,使用和ngResource $资源调用,但似乎Ajax调用总是为时已晚,NG-电网已经被渲染后。 网格渲染的标题,但没有填充数据。 下面的代码和一个片段的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>