Last active
December 16, 2015 22:20
-
-
Save mgonto/5506668 to your computer and use it in GitHub Desktop.
Enhanced promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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