Skip to content

Instantly share code, notes, and snippets.

@ekazakov
Created October 15, 2015 21:55
Show Gist options
  • Save ekazakov/770fe84bbd3b6e68bdee to your computer and use it in GitHub Desktop.
Save ekazakov/770fe84bbd3b6e68bdee to your computer and use it in GitHub Desktop.
Pre resolve promises
angular.module('app', [])
.decorator('$controller', function ($delegate) {
return function () {
var result = $delegate.apply(null, arguments);
return result;
};
})
.factory('lib',function ($q) {
return $q.when('Hello');
})
.controller('Foo', resolveDeps(/*@ngInject*/ function Foo (lib) {
this.x = 2;
this.msg = lib;
}));
function resolveDeps (ctrl) {
const deps = angular.injector().annotate(ctrl);
return ['$q'].concat(deps, function ($q) {
var args = Array.prototype.slice.call(arguments, 1);
$q.all(args).then(function(results) {
ctrl.slice(-1)[0].apply(this, results);
}.bind(this));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment