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.
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!
I haven't worked with Restangular directly, but your POST probably needs to return a JSON object with the ID. Then, your success function has to accept it as a parameter.
firstAccount.post("Buildings", myBuilding).then(function(resp) {
console.log(resp.id); // if the JSON obj has the id as part of the response
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With