I'm trying to set up routing with the angular-ui-router plugin for angular. Before anything else should happen on the page (no matter which route), the user's data needs to be loaded. Then based on the user's data (id, username, etc.) other data components necessary for the route can be loaded.
Is there a pattern for this scenario? I was thinking one way to solve this would be to add the user data as a resolve on every route. However, not only does this seem very redundant and inefficient, but it also doesn't work (see code below).
Here's a code sample that doesn't work because the collectionlist
resolve doesn't wait for the userpanel
resolve to finish (and I understand that that's the expected behavior):
.state('default', {
url: '/',
views: {
'userpanel' : {
templateUrl: 'js/partials/user_panel.html',
controller: 'userController',
resolve: {
user: function(UserResourceLoader) {
return UserResourceLoader();
}
}
},
'collectionlist' : {
templateUrl: 'js/partials/collection_list.html',
controller: 'collectionsController',
resolve: {
collectionsByUser: function(CollectionsByUserLoader, User) {
return CollectionsByUserLoader(User.data.id);
}
}
}
}
})
Any suggestions for this would be very helpful.