title: AngularJS : How to flatten this Promise chain?
body: <p>I have the following code:</p>
  
  <pre><code>someService.fnReturnsPromise()
      .then(function () {
          return someService.fnReturnsAnotherPromise(someArg);
      })
      .then(function (resultsOfSecondFn) {
          // do stuff with results
      });
  </code></pre>
  
  <p>I feel as if this should work; however, <code>resultsOfSecondFn</code> isn't actually the results, it's the promise itself that I returned. To make it work the way I want, I have to do this:</p>
  
  <pre><code>someService.fnReturnsPromise()
      .then(function () {
          return someService.fnReturnsAnotherPromise(someArg);
      })
      .then(function (promiseReturn) {
          promiseReturn.then(function (results) {
              // do stuff with results
          });
      });
  </code></pre>
  
  <p>This is the pseudo-code for <code>fnReturnsAnotherPromise</code>:</p>
  
  <pre><code>someService.fnReturnsAnotherPromise = function (arg1) {
      return anotherService.anotherFnThatReturnsPromise(arg1);
  };
  </code></pre>
  
  <p>So really, it's just one extra layer, but a promise is getting returned either way. The code for <code>anotherFnThatReturnsPromise</code> is the simple paradigm of <code>$q.defer()</code>, <code>return dfd.promise</code> with some <code>resolve()</code>s.</p>