title: Nested promises in ui-router resolve
body: <p>I have been struggling for a while with the following problem:</p>
  
  <p><em>I would like to get some data before the view shows, (resolve). But some of the data is dependend on the result of another promise.</em></p>
  
  <p><em>It goes like this: I get the job id (index) from the $stateParams and look up the data in my Service. Once it is completed, from this result (the job), I can look up the settings and floors (each from a different service), both return a promise.</em></p>
  
  <p>What I've came up so far</p>
  
  <pre><code>jobinfo: function(Jobs, Floor, JobSetting, $stateParams, $q) {
  
      var defer = $q.defer();
  
          Jobs.getByIndex($stateParams.index)
          .then(function(job) {
              console.log('got jobs');
              $q.all({floors: Floor.getByJob(job), settings: JobSetting.getByJob(job)})
              .then(function(info) {
                  console.log('got info');
                  defer.resolve([job, info.floors, info.settings]);
              });
          });
  
      return defer.promise;
  }
  </code></pre>
  
  <p><em>Take 2</em></p>
  
  <pre><code>jobinfo: function(Jobs, Floor, JobSetting, $stateParams, $q) {
  
      return Jobs.getByIndex($stateParams.index)
          .then(function(job) {
              console.log('got jobs');
              return $q.all({floors: Floor.getByJob(job), settings: JobSetting.getByJob(job)})
              .then(function(info) {
                  console.log('got info');
                  return [job, info.floors, info.settings];
              });
          });
  }
  </code></pre>
  
  <p>Both seem to fail, I do not even get a <code>console.log</code> back.</p>
  
  <p>PS: I left the rest of the code out, obviously they are wrapped in an </p>
  
  <pre><code>resolve: {
  ...
  }
  </code></pre>
  
  <p>and defined in the right place.</p>
  
  <p>Could someone be so gentle to point me out in the right direction ?</p>
  
  <hr>
  
  <p>The solution I ended up with was the following: (thanks to <em>avcajaraville</em>)</p>
  
  <pre><code>job: function(Jobs, $stateParams) {
      return Jobs.getByIndex($stateParams.index);
  },
  
  floors: function(Floor, job) {
      return Floor.getByJob(job);
  },
  
  settings: function(JobSetting, job) {
      return JobSetting.getByJob(job);
  }
  </code></pre>