Skip to content

Instantly share code, notes, and snippets.

@fiznool
Created September 25, 2014 10:48
Show Gist options
  • Save fiznool/bf5c14673ef5528c3b57 to your computer and use it in GitHub Desktop.
Save fiznool/bf5c14673ef5528c3b57 to your computer and use it in GitHub Desktop.
Add extra functions to the $q Angular service.
'use strict';
angular.module('q-extra', [])
.config(['$provide', function($provide) {
$provide.decorator('$q', ['$delegate', function($delegate) {
if(angular.isUndefined($delegate.resolve)) {
$delegate.resolve = function($q) {
return function(val){
var dfd = $q.defer();
dfd.resolve(val);
return dfd.promise;
};
};
}
return $delegate;
}]);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment