restangular icon indicating copy to clipboard operation
restangular copied to clipboard

`plain()` doesn't remove custom methods

Open giladbeeri opened this issue 10 years ago • 1 comments

I have a Restangular object returned from server, it has several Restangular methods, server data and one custom method that I added using addRestangularMethod(). After calling plain() on the object, the original Restangular properties are removed, but the custom one isn't. I would like to be able to get a raw JSON object - the raw response from the server (or after applying interceptors, it doesn't matter in my case). Because plain() doesn't do the job perfectly, currently I use something like angular.fromJson(angular.toJson(res.plain())) which removes also the custom method left after plain.

giladbeeri avatar Aug 16 '15 18:08 giladbeeri

Hi. If you don't want to see your custom methods in response, you can simply check if there is a request or response. For e.g.: RestangularProvider.setOnElemRestangularized(function (elem, isCollection, what, ra) { if (!elem.fromServer) { elem.YOUR_CUSTOM_METHOD = function () { ... }; } return elem; });

zombitrafik avatar Nov 05 '18 09:11 zombitrafik