I read about how to inject dependency in cofing method of the module. I created provider for my service like this
app.provider("securitySvc", function securitySvcProvider () {
this.$get = ['Authorizations', '$q', 'routeSvc', function securitySvcFactory (Authorizations, $q, routeSvc) {
return new securityService(Authorizations, $q, routeSvc);
}];
});
When I try to use it I get instance with a $get method instead of newed up securityService. What am I doing wrong?
app.config( ['$routeProvider', 'routes', 'securitySvcProvider', routeConfigurator]);
function routeConfigurator($routeProvider, routes, securitySvc) {
// HERE securitySvc is instance with a $get method, not newed up securitySvc
}
Note that everywhere else, in controllers, securitySvc is injected correctly.
However, if do follwing in "run" method of module
app.run(function ($rootScope, securitySvc) {
$rootScope.hasPermission = function (authorizationName) {
return securitySvc.hasAuthorization(authorizationName);
};
}
Then if I reference it in routeConfiguration through $rootScope.hasPermission
it works fine. My goal was to avoid using scope and just use service. Can it be done?