mgonto / restangular

AngularJS service to handle Rest API Restful Resources properly and easily
MIT License
7.87k stars 841 forks source link

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

Open slvrtrn opened 9 years ago

slvrtrn commented 9 years ago

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.

uetkaje commented 7 years ago

+1 Plain method should just remove Restangular fields.

rosostolato commented 6 years ago

Has this issue been fixed?

Malex commented 5 years ago

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 commented 5 years ago

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

Malex commented 5 years ago

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