Skip to content

Instantly share code, notes, and snippets.

@mgonto
Created May 3, 2013 06:19
Show Gist options
  • Save mgonto/5507508 to your computer and use it in GitHub Desktop.
Save mgonto/5507508 to your computer and use it in GitHub Desktop.
Restangular Promise Enhanced
var buildings = Restangular.all("buildings").getList();
// New promise after adding the new building
// Now you can show in scope this newBuildings promise and it'll show all the buildings
// received from server plus the new one added
var newBuildings = buildings.push({name: "gonto"});
var newBuildingsSame = buildings.call("push", {name: "gonto"});
// This is a promise of a number value. You can show it in the UI
var lengthPromise = buildings.get("length");
lengthPromise.then(function(length) {
// Here the length is the real length value of the returned collection of buildings
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment