title: Angular-ui-router: managing dependencies with resolve
body: <p>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.</p>
  
  <p>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 <strong>every</strong> route. However, not only does this seem very redundant and inefficient, but it also doesn't work (see code below). </p>
  
  <p>Here's a code sample that doesn't work because the <code>collectionlist</code> resolve doesn't wait for the <code>userpanel</code> resolve to finish (and I understand that that's the expected behavior):</p>
  
  <pre><code>.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);
                      }
                  }
              }
          }
      })
  </code></pre>
  
  <p>Any suggestions for this would be very helpful.</p>