Getting Response from Restangular POST

Issue

How do I get the response object after I send a Restangular POST?

 firstAccount.post("Buildings", myBuilding).then(function() {
   console.log("Object saved OK");
 }, function() {
  console.log("There was an error saving");
 });

I’m trying to get the new object id.

Thanks.

Solution

I’m the creator of Restangular. Flim is right :).

In the promise then you get the object returned from the server 🙂

firstAccount.post("Buildings", myBuilding).then(function(addedBuilding) {
   console.log("id", addedBuilding.id);
 }, function() {
  console.log("There was an error saving");
 });

Thanks!

Answered By – mgonto

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.