我开始用ngTable的现有例的修改有点用ngResource不工作。使用资源工厂它填充数据,但搜索和排序不起作用。
http://codepen.io/anon/pen/yVGKMZ
创建上方的笔。
var app = angular.module("myApp", ["ngTable", "ngResource", "ngTableDemoFakeBackend"]);
app.factory('orderResource', function ($resource) {
return $resource('https://jsonplaceholder.typicode.com/posts');
});
(function() {
app.controller("demoController", demoController);
demoController.$inject = ["NgTableParams", "$resource", "orderResource"];
function demoController(NgTableParams, $resource, orderResource) {
//debugger;
var ordersGet = orderResource.query({ });
var Api = $resource("/data");
this.tableParams = new NgTableParams({}, {
getData: function (params) {
// **** Section 1 *** sorting and filter does not work
return ordersGet.$promise.then(function (response) {
params.total(100);
return response;
// **** Section 1 ***
//****Section 2 *** this works fine
// return Api.get(params.url()).$promise.then(function(data) {
// params.total(data.inlineCount);
// return data.results;
//****Section 2 ***
});
}
});
}
})();
<div ng-app="myApp">
<div ng-controller="demoController as demo">
<table ng-table="demo.tableParams" class="table table-bordered table-striped table-condensed">
<tr ng-repeat="row in $data track by row.id">
<td data-title="'iss'" filter="{id: 'number'}" sortable="'id'">{{row.id}}</td>
</tr>
</table>
</div>
</div>
在代码中,如果你对此有何评论第1节和未注释部分2你可以观察它的工作。 我也试过简单的$ http它没有工作。
我想这一点,并没有奏效。 app.factory('orderResource',function($ resource){ return $ resource('https://jsonplaceholder.typicode.com/posts',{},{ get:{method:'GET'}, 更新:{方法:'POST'} }); }); –