Resolve common dependencies for routes
$ npm install --save angular-global-resolve
angular
.module('app', [
require('angular-global-resolve')
])
angular
.module('expenses', [])
.config(routes)
function routes($stateProvider, globalResolveProvider) {
globalResolveProvider.addGlobalDependencies($stateProvider, {
user: function (userService) {
'ngInject';
return userService.getUser();
}
});
}
NOTICE:
You can use either $stateProvider (ui-router) and $routeProvider (ngRoute)