Created
May 20, 2014 14:01
-
-
Save teropa/ddf94bf23fe9e8bdaded to your computer and use it in GitHub Desktop.
$q.now() - an immediately resolved promise oneliner for Angular.js
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
module.config(['$provide', function($provide) { | |
// Add a method to $q that returns a promise resolved to | |
// the given value. Use as: $q.now(42) | |
$provide.decorator('$q', ['$delegate', function($delegate) { | |
$delegate.now = function(value) { | |
var d = $delegate.defer(); | |
d.resolve(value); | |
return d.promise; | |
}; | |
return $delegate; | |
}]); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or, as it turns out, you could just use when