restangular icon indicating copy to clipboard operation
restangular copied to clipboard

plain() method removes fields that was added to data in addResponseInterceptor

Open slvrtrn opened this issue 9 years ago • 5 comments

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.

slvrtrn avatar Aug 16 '15 17:08 slvrtrn

+1 Plain method should just remove Restangular fields.

uetkaje avatar Aug 05 '17 06:08 uetkaje

Has this issue been fixed?

rosostolato avatar May 22 '18 19:05 rosostolato

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

Malex avatar Aug 01 '19 07:08 Malex

Also, to clarify: that happens even if you add the field anywhere else in your application code, not just the interceptor

Malex avatar Aug 01 '19 07:08 Malex

Also if I changed the value somewhere (i.e. in an ngModel 2-way binding), the plain will return the old value actually

Malex avatar Aug 01 '19 07:08 Malex