mgonto / restangular

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

`plain()` doesn't remove custom methods #1221

Open giladbeeri opened 9 years ago

giladbeeri commented 9 years ago

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.

zombitrafik commented 6 years ago

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; });