I'm currently in the process of setting up resolves for my admin panel routes and I'm pondering the best way to store them without cluttering my router with methods. Here's what I have so far:
when('/admin', {
templateUrl: 'app/private/admin/view.html',
controller: 'admin',
resolve: ['$q', '$location', 'api', function($q, $location, api){
var deferred = $q.defer(),
session = api.session();
if(session){
deferred.resolve(session);
} else {
api.authorise().success(function(response){
deferred.resolve(response);
}).error(function(error){
$location.path('/login');
deferred.reject(error);
});
}
return deferred.promise;
}]
})
I believe a more organized approach would be to keep the resolves within the controller used for that route, like this:
when('/admin', {
templateUrl: 'app/private/admin/view.html',
controller: 'admin',
resolve: adminCtrl.resolve
})
Unfortunately, the admin controller is not directly accessible from the configuration, meaning I might need to use a provider which could lead to a messy codebase as the application grows.
How do you manage your resolves? Is there a way to store them directly in the controller itself?