Getting Response from Restangular POST

Hass picture Hass · Jun 16, 2013 · Viewed 12.1k times · Source

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.

Answer

mgonto picture mgonto · Jun 19, 2013

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!