tôi bắt đầu với một ví dụ hiện tại về ngTable đã sửa đổi nó một chút để sử dụng ngResource. sử dụng nhà máy tài nguyên, nó điền dữ liệu nhưng tìm kiếm và sắp xếp không hoạt động.
http://codepen.io/anon/pen/yVGKMZ
Tạo bút ở trên.
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>
Trong mã nếu bạn nhận xét phần 1 và bình luận un phần 2 bạn có thể quan sát nó làm việc. tôi cũng đã thử đơn giản $ http nó đã không làm việc là tốt.
tôi đã cố gắng này, không làm việc. app.factory ('orderResource', hàm ($ resource) { trả về $ resource ('https://jsonplaceholder.typicode.com/posts', {}, { nhận được: {method: 'GET'}, cập nhật: {method: 'POST'} }); }); –