restangular
restangular copied to clipboard
plain() method removes fields that was added to data in addResponseInterceptor
Hello.
I'm trying to store some pagination information in $pagination
field of my data object using addResponseInterceptor
Code example:
return RestangularProvider.addResponseInterceptor((data, operation, what, url, response) => {
var headers = response.headers();
if ('x-pagination-total' in headers) {
data.$pagination = {
total: Number(headers['x-pagination-total']),
// snip
};
}
return data;
});
in my service i'm using plain()
methods to strip out restangular fields
return Restangular.all('users').getList().then((restangularized) => {
return restangularized.plain();
}
and after plain()
method call custom $pagination
field is removed.
Is it possible to add an exception for some fields without workarounds like:
var data = restangularized.plain();
data.$pagination = restangularized.$pagination;
return data;
?
Thanks in advance.
+1 Plain method should just remove Restangular fields.
Has this issue been fixed?
This is still happening. This is a lot worse, for instance, if you have a resource which actually has some field left undefined in the server, then you change it and need to send it as incapsulated obj in another request, since you have to strip restangular fields but you cannot invoke plain apparently
Also, to clarify: that happens even if you add the field anywhere else in your application code, not just the interceptor
Also if I changed the value somewhere (i.e. in an ngModel 2-way binding), the plain will return the old value actually