Skip to content

Instantly share code, notes, and snippets.

@mgonto
Last active December 16, 2015 22:20
Show Gist options
  • Select an option

  • Save mgonto/5506668 to your computer and use it in GitHub Desktop.

Select an option

Save mgonto/5506668 to your computer and use it in GitHub Desktop.
Enhanced promises
// This will return a promise of an Array
var promisedArray = $q.when([1,2,3]);
//Normal way of getting length in angular
promisedArray.then(function(arr) {
var length = arr.length;
// Do something with length in callback
})
//Using promises transformation
// This is a promise of a number
var lengthPromise = promisedArray.get('length');
//Calling methods
var biggerArrayPromise = promisedArray.call("push", {name: "Gonto"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment