$routeProvider resolve
feature in AngularJS allows for injecting additional dependencies to the controller function. How can we combine this with explicit dependency injection declaration?
Example:
angular.module('myModule', [])
.config(function($routeProvider) {
$routeProvider.
when('/tabOne', { templateUrl : 'tabOne.html', controller: TabOne,
resolve: {
someDependency: SomeDependency.factoryFunction
}
});
});
Then:
TabOne.$inject = [ '$scope', 'someFirstService', 'someOtherService' ];
In the example above, two services are injected into the TabOne
controller (someFirstService
and someOtherService
). However, I want the route to change only after someDependency
has been resolved and injected into TabOne
as well. If I simply add someDependency
to the Controller function's arguments list, it will result in a DI error.
Any suggestions on how to achieve this?