Restangular get clean response object from POST request

Issue

I’m trying to use Restangular service, but I have gotten one problem which I can’t solve. For example I’m doing the POST request and I want to get clean response Object, but in my response Object wrapped all Restangular methods, I know may be it’s a feature, but I need my clean response :))

 this.Restangular.one("auth").post("login",data).then(function(resp){
                console.log(resp);
                // in response object wrapped all Restangular methods 

            }

Solution

You can get the plain element using .plain() from response

 this.Restangular.one("auth").post("login",data).then(function(resp){
      console.log(resp.plain());
      //Returns the plain element received from the server without 
      //any of the enhanced methods from Restangular. 
     //It's an alias to calling Restangular.stripRestangular(elem)
 }

You need to use Restangular version 1.4.0

Plunkr – http://plnkr.co/edit/qDAyPqywC27in9wnlAHF

Answered By – hutingung

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.