title: Chaining promises with $q in Angular
body: <p>I am trying to chain promises so that doQuery(0) executes then doQuery(1), etc... sequentially until doQuery(9). </p>
  
  <p>My problem is that i is always equals to 10 in the callback function.</p>
  
  <p>doQuery(0) executes then doQuery(10).</p>
  
  <p>How do I pass each value of i in the callback function?</p>
  
  <pre><code>var promise = doQuery(0);
  for (var i = 1; i &lt; 10; i++) {
      promise = promise.then(function() {
          doQuery(i);
      });
  };
  </code></pre>