Skip to content

Commit

Permalink
feat($rti): a runtime injected function proxy provider
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Sep 26, 2014
1 parent d94d3d1 commit 5c5aa5f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,34 @@ angular.module('ui.router.state', ['ui.router.router', 'ui.router.util']);
angular.module('ui.router', ['ui.router.state']);

angular.module('ui.router.compat', ['ui.router']);

/**
* $rtiProvider: Runtime Injector Provider
* Declare functions that are injected at runtime within config blocks.
* Creates a no-argument function proxy. The target `injectedFunction` will be injected
* when the no-argument proxy is invoked.
*/
angular.module('ui.router').provider('$rti', function() {
var _injector;

this.invoke = function(injectedFunction, self, locals) {
if (_injector === undefined) throw new Error("Can only be used at runtime");
return _injector.invoke(injectedFunction, self || this, locals);
};

this.makeRuntimeFn = function(injectedFunction, self, locals) {
return function() {
return invoke(injectedFunction, self, locals);
}
};

this.$get = ['$injector', function($injector) {
_injector = $injector;
return { };
}];

return this;
});

angular.module('ui.router').run(function($rtiProvider) { });

0 comments on commit 5c5aa5f

Please sign in to comment.