nested resolves
A really cool feature of UI Router are nested resolves. Which means your second resolve will wait for the first resolve to finish, and use that info. ( quick example from : https://medium.com/opinionated-angularjs/advanced-routing-and-resolves-a2fcbf874a1c#e7cc ) e.g. :
$stateProvider.state('users.profile', {
url: '/:id',
templateUrl: 'views/users.profile.html',
controller: 'UsersController',
resolve: {
user: function($stateParams, UserService) {
return UserService.find($stateParams.id);
},
tasks: function(TaskService, user) {
return user.canHaveTasks() ?
TaskService.find(user.id) : [];
}
}
});
Is there a way to accomplish this with deferred bootstrap? The use-case would be that the first resolve loads the app configuration, and the second resolve checks and syncs the user session based on the app config data. ( Something like this : http://grab.by/EwoI )
Yes, this really is a cool feature. It could be implemented in angular-deferred-bootstrap if the resolve functions would be chained and the already resolved values would be passed as locals to the next resolve function. (see: https://docs.angularjs.org/api/auto/service/$injector)
With the current version you can of course chain multiple promises inside of one resolve function, but it is not yet possible to make multiple constants available to your app.
Lol, I was just going to write a post about this... I would love to:
USER: ['userService', function (userService) {
return userService.getCurrentUser();
}],
LANGUAGE: [languageService, function (languageService, USER) {
return languageService.getLanguage(USER.preferredLang);
}]