title: Iterate over array when forEach loop is all done
body: <p>Im trying to iterate over an array that I construct from multiple http calls inside a <code>angular.forEach()</code></p>
  
  <p>the function</p>
  
  <pre><code>$scope.ticket_stats = function(){
      //cleaning variables
      $scope.data_set = [];
      $scope.closed_tickets = [];
  
      //fetching time stamps (epoch)
      $scope.time_frame = time_period.days(7);
  
                //calling data using time stamps
                angular.forEach($scope.time_frame, function(item) {
                    //debug
                    console.log(item);
  
                    var promise = tickets.status("closed", item);
  
                    promise.success(function(data){
                        console.log(data);
                        $scope.closed_tickets.push(data[0].datapoints[0][0]); // returns a numerical value
                    });
  
                });
                //SEE MESSAGE BELOW
                $scope.data_set.push($scope.closed_tickets);
  
  }
  </code></pre>
  
  <p>the last line <code>$scope.data_set.push()</code> is working but increment itself over time once calls return data. I would like this line to be executed once everything within the for Each loop is all done. I need to iterate over the <code>$scope.closed_tickets</code> array afteward to play (addition) data inside it and build up a second array.</p>
  
  <p>here are the services used in this function:</p>
  
  <pre><code>// CALL TICKETS STATS
  app.service('tickets', function($http){
  
      this.status = function(status, date){
          var one_snap = date - 100;
          var url = "/url/render?format=json&amp;target=sum(stats.tickets."+status+")&amp;from="+one_snap+"&amp;until="+date+"";
          return $http.get(url);
      };            
  });
  
  // TIME STAMPS MATHS
  app.service('time_period', function(){
      var currentDate = parseInt((new Date).getTime()/1000);
  
      this.days = function(number){
          var pending = [];
          for (var i = number; i &gt; 0; i--) {
              pending.push(currentDate - (87677*i));
          }
          return pending;
      }; 
  });
  </code></pre>
  
  <p>I search for information and found out about the <code>$q.all()</code> service but didn't manage to make this work the way I want.</p>
  
  <p>Any advices would be welcomed!
  Thanks!</p>