I know I can't dependency inject a factory into a config as they only take providers, which as I understand it are just a fully customizeable services that factories and services inherit. So I thought I'd try creating a bunch of small route providers so I didn't have to add commonly reused resolve actions as anonymous functions in variables within the config, which just gets messy after awhile.
Provider
angular.module('project.app.service', [])
.provider('UserAuthService', function () {
this.$get = ['UserResource', function (UserResource) {
return {
getUser: getUser
};
function getUser() {
return UserResource.auth().$promise;
}
}];
}),
...
Routes Including Provider Module
angular.module('project.app.route', ['project.app.service'])
.config(['$stateProvider', '$urlRouterProvider', 'UserAuthServiceProvider',
function ($stateProvider, $urlRouterProvider, UserAuthServiceProvider) {
$stateProvider
...
.state('dashboard.index', {
url: "/map",
templateUrl: "templates/dashboard/map/map.html",
controller: 'MapController',
controllerAs: 'mapCtrl',
resolve: {
UserAuth: UserAuthServiceProvider.getUser()
}
})
...
});
The docs state that only the $get function can be injected, but it throws this error even though it appears like it should work:
TypeError: UserAuthService.getUser is not a function
This seems like it should work from the docs and examples, and with credit to the comments below for providing help and brainstorming the issue.
Is there a single line resolve parameter solution to make this more modular, or should I just drop anonymous functions at the top of the ui-route config, that inject a factory, and forget about this?