title: Angular service calling another service
body: <p><strong>I'm making a simple Angular app to manage incomes</strong>. The incomes come from projects that I store in json (for testing purpose).</p>
  
  <p>So, basically, I use a service in Angular to get this json and I would like to have another service that call Projects service and filter the incomes of each projects.</p>
  
  <p>Here's the code : </p>
  
  <pre><code>facturateApp.service('Projects', function($http){     
  
  
   var Projects = {
        async: function() {
  
          var promise = $http.get('base.json').then(function (response) {            
            return response.data;
          });
          return promise;
        }
      };
      return Projects;
  
  
  });
  
  facturateApp.service('Incomes', function(Projects){    
      var incomes = []; 
      Projects.async().then(function(d) {
        var projects = d;
  
        angular.forEach(projects, function(project){
  
          if(typeof(project.account.accountAmount) == 'number' &amp;&amp; project.account.accountAmount &gt; 0){
              var newIncome = {};
              newIncome.projectName = project.projectName;
              newIncome.clientName = project.clientName;
              newIncome.typeIncome = "Accompte";
              newIncome.amount = project.account.amountAccount;
              newIncome.date = project.account.accountDate;
              newIncome.notes = project.account.accountType;
              incomes.push(newIncome);
  
  
          }
  
  
  
        });
        angular.forEach(projects, function(project){
  
  
          if (typeof(project.total.totalAmount) == 'number' &amp;&amp; project.total.totalAmount &gt; 0){
              var newIncome = {};
              newIncome.projectName = project.projectName;
              newIncome.clientName = project.clientName;
              newIncome.typeIncome = "Accompte";
              newIncome.amount = project.total.totalAmount;
              newIncome.date = project.total.totalDate;
              newIncome.notes = project.total.totalType;
              incomes.push(newIncome);
  
  
          }
  
  
        });
  
      });
      console.log(incomes); // still returns [];
      return incomes;
  
  });
  </code></pre>
  
  <p><strong>My problem is that the last log returns an empty array</strong>. Actually it works as supposed : <code>incomes</code> is returned before <code>Projects.async().then(function(d)</code> is executed.</p>
  
  <p>But I don't know wait for this function to be executed before returning <code>incomes</code> in a service that call another service...</p>
  
  <p>Any help ?</p>