title: AngularJS : assign asynchronous data to an array element in a for loop
body: <p>I'm trying to assign array elements in a for loop with asynchronous results of a call to a <code>ngResource</code> action.</p>
  
  <pre><code>for ( var i = 0; i &lt; projs.length; i++) {
      $scope.projets[i].redacteur = new Object(); // the Object where the result will be stored
      var param = new Object();
      param.email = projs[i].redacteurEmail;
      Agent.read(param, function(data) {
          $scope.projets[i].redacteur = data;
      });
  
  
  }
  </code></pre>
  
  <p>The problem is : when the callback function is executed (when the data is received), <code>i</code> is out of bounds (it passed the last <code>i++</code>). Then the data received is assigned to a nonexistent object.</p>
  
  <p>Any idea of a solution to this issue ?</p>