title: Promise dependency resolution order in angular ui-router
body: <p>I have set up a top-level controller that is instantiated only when a promise (returned by a <code>Config</code> factory) is successfully resolved. That promise basically downloads the Web app configuration, with RESTful endpoints and so on.</p>
  
  <pre><code>$stateProvider
    .state('app', {
      url: '/',
      templateUrl: 'views/_index.html',
      controller: 'MainCtrl',
      resolve: {
        config: 'Config'
      }
    });
  </code></pre>
  
  <p>This setup allows me to kind-of assert that the configuration is properly loaded before any lower controller gets a chance to use it.</p>
  
  <p>Now I need to inject, in a deeper nested controller, another <code>factory</code> that uses <code>Config</code> and only works when it is resolved (look at it like a <code>$resource</code> wrapper that needs some Web service URLs). If I do:</p>
  
  <pre><code>$stateProvider
    .state('app.bottom.page', {
      url: '/bottom/page',
      templateUrl: 'views/_a_view.html',
      controller: 'BottomLevelCtrl',
      resolve: {
        TheResource: 'MyConfigDependingResource'
      }
    });
  </code></pre>
  
  <p>it looks like the <code>resolve</code> evaluation order does not follow the controller hierarchy from top to bottom, but from bottom to top, therefore:</p>
  
  <ol>
  <li><code>app.bottom.page</code> is entered</li>
  <li><code>ui-router</code> attempts to resolve <code>MyConfigDependingResource</code>, but the injection fails,
  because <code>Config</code> has never been initialized</li>
  <li>The <code>ui-router</code> resolution stops because of an error (without even throwing <code>Error</code>s, but that's another issue), and <code>Config</code> is never initialized by the top level controller</li>
  </ol>
  
  <p>Why is <code>ui-router</code> resolving dependencies in a reverse order? How can I easily resolve my <code>TheResource</code> object <strong>after</strong> the  top level <code>MainCtrl</code> has resolved <code>Config</code> (without relying on <code>$inject</code>, of course)?</p>
  
  <p><strong>UPDATE</strong>: from <a href="http://plnkr.co/edit/LmDKZ1nhyGwqDF19Ckhb?p=preview" rel="noreferrer">this plnkr's log</a> you can see that the top level <code>resolve</code> is attempted only after the nested controller has started its own resolving process.</p>