Here is the API structure I am working with:
{
"meta": {
"total_item": 1,
"number_of_pages": 1,
"page_number": 1,
"status": "Success"
},
"data": [
{
"name": "Operator 1",
"short_name": "OP1",
"_id": "534d69bba758b3b7839ba7b9",
"__v": 0,
"users": [
"532ef6e28b42970ab797444f"
]
}
]
}
In my Angular application, I am using $resource to interact with this API. Here is a snippet of the code:
var apiDataTransformer = function ($http) {
return $http.defaults.transformResponse.concat([
function (data, headersGetter) {
var result = data.data;
result.meta = data.meta;
console.log(result);
return result;
}
])
};
angular.module('ua.common').factory('uaApi', function($resource, $http){
var factory = {};
factory.operator_ressource = $resource(
'/operators/:operatorId',
{},
{'query': {method: 'GET', isArray: true, transformResponse: apiDataTransformer($http) } }
);
return factory;
})
When I query these resources and check the response in the console, some unexpected behavior occurs. The meta object gets lost in the process even though I used transformResponse to retain all data.
Is there a way to preserve the meta object while using $resource in Angular for pagination purposes?