I know this question is little bit old. But I think answer doesn't cover main problem - how to get pagination information and how to keep Resource features for list of objects.
You have basicly two solutions, pass paginator data into headers in transform message or use $http and then instantiate items manually.
1.Transform message
Here i redefine query to put pagination data into headers.
Headers is not an array - it is "headersGetter" which returns header by calling headers('Header-Name') and returns inner object by calling headers(). I have to set header lowercase.
var PAGINATION_TOTAL = 'pagination-total-elements';
var PAGINATION_SIZE = 'pagination-size';
...
.factory('BeerResourceFactory', function($resource, API_URI) {
return $resource(API_URI + '/beer/:id',
{'id': '@id'},
{
'update': {method: 'PUT'},
'query' : {method: 'GET', isArray:true, transformResponse : function(data, headers) {
var jsonData = JSON.parse(data);
headers()[PAGINATION_TOTAL] = jsonData.totalElements;
headers()[PAGINATION_SIZE] = jsonData.size;
return jsonData.content;
}}
});
})
After that I define service which encapsulate this and take pagination from headers. Sudenly we cannot use $promise.then() and retrurn result because promise gets only result as argument and not the headersGetter, so we have to use ordinary callback and create own promise.
.service('beerService', function(BeerResourceFactory, $q) {
this.query = function(filter) {
var defer = $q.defer();
BeerResourceFactory.query(filter, function(result, headers) {
var promiseResult = {
beers: result,
paging: {
totalItems: headers(PAGINATION_TOTAL),
perPage: headers(PAGINATION_SIZE)
}
};
defer.resolve(promiseResult);
});
return defer.promise;
}
2.Using $http and instantiate Resource
When using $http instead of resource, there is problem that you still want to use elements of array as resource instances and be able to call $save / $delete, so it is possible to instantiate them manually. Here you can also use ordinary promise as ussual.
.service('beerService', function($http, BeerResourceFactory, API_URI) {
this.query = function(filter) {
return $http.get(API_URI + '/beer', {params: filter})
.then(function(response) {
var transformedList = response.data.content.map(function(element) {
return new BeerResourceFactory(element);
});
return {
beers: transformedList,
paging: {
totalItems: response.data.totalElements,
perPage: response.data.size
}
};
});
};
I would prefer second solution, because its more simple.