title: AngularJS 1.x getting and chaining multiple API
body: <p>I'm trying to get multiple APIs to access data but after all this returned empty data without displaying any error. Here is my code:</p>
  
  <pre><code> var myApp = angular.module("myApp", []);
  
   // Main controller
   myApp.controller("appCtrl", ["$scope", "$http", function($scope, $http){
  
     // Variables of stations, train number and departure date
     var sta = "";
     var trainNum = "";
     var deptDate = "";
  
     // Get stations data  
     $http.get("https://rata.digitraffic.fi/api/v1/metadata/stations.json").then(function(response){
       // Load the stations data
       $scope.stations = response.data;
  
       // Access all stations data
       angular.forEach($scope.stations, function(value,index){
  
         sta = $scope.stations[index].stationShortCode;
         //console.log(sta);
  
         // Get train data from each station
         $http.get("https://rata.digitraffic.fi/api/v1/live-trains?station=" + sta + ".json").then(function(response){
           $scope.trains = response.data;
           //console.log(response.data);
  
           // Access all train data
           angular.forEach($scope.trains, function(value, index){
             trainNum = $scope.trains[index].trainNumber;
             deptDate = $scope.trains[index].departureDate;
  
           // Get all train compositions data from all train data above
           $http.get("https://rata.digitraffic.fi/api/v1/compositions/" + trainNum + "?departure_date=" + deptDate + ".json").then(function(response){
             $scope.trainCompositions = response.data;
             //console.log(response.data);
           });
         });
       });
     });
   });
  }]);
  </code></pre>
  
  <p>The first API url responded well, however from the second one it returned empty arrays. I wanted to get all data of the railways stations from the 1st API, then concat each station into the 2nd API url, after that I want to get data of trainNum (train number) and deptDate (departure date) to concat into the 3rd API url to access all data of the train compositions there.  </p>
  
  <p>Here is examples of </p>
  
  <p>2nd API url: <a href="https://rata.digitraffic.fi/api/v1/live-trains?station=HKI" rel="nofollow noreferrer">https://rata.digitraffic.fi/api/v1/live-trains?station=HKI</a>  (where HKI is Helsinki station).</p>
  
  <p>3rd API url: <a href="https://rata.digitraffic.fi/api/v1/compositions/960?departure_date=2017-05-02" rel="nofollow noreferrer">https://rata.digitraffic.fi/api/v1/compositions/960?departure_date=2017-05-02</a>  (where 960 is the train number, and 2017-05-02 is departure date).</p>
  
  <p>Thank you guys in advance.</p>