title: Angular foreach wants to wait until response for single call
body: <p>I have thousands of records in my array. I wish to perform  some function on each element of my array. Though my functions works fine, but I want to delay the call of next item until first is parsed properly. I don't have relevancy of return either it is true or not. I just wish to delay loop until single item is parsed. </p>
  
  <p>I tried.</p>
  
  <pre><code> $scope.getInfo = function (funcName) {
  
              $http.get(Youtube.getDetails(funcName)).success(function (data, status, headers, config) { // this callback will be called asynchronously when the response is available
                  if (!angular.isUndefinedOrNull(data.nextPageToken)) {
                      $scope.form.playlistToken = data.nextPageToken;
                  } else {
                      $scope.form.playlistToken = "";
                      $scope.form.playlistUrl = "";
                  }
                  if (data.items.length &gt; 0) {
                      angular.forEach(data.items, function (value, key) {
                          var youTubeData = Youtube.parseVideoDetail(value);
                          if (!angular.isUndefinedOrNull(youTubeData.videoId)) {
                              Video.find({filter: {where: {videoId: youTubeData.videoId}}}).$promise.then(function (data) {
                                  if (data.length == 0) {
                                      Video.create(youTubeData).$promise.then(function (value, responseHeader) {
                                          $scope.items.splice(0, 0, youTubeData);
                                          youTubeData = {};
   //                                       $scope.form.url = "";
                                          toastr.success("Record saved successfully", "Success");
                                      }, function (reason) {
                                          toastr.error("Video can't be saved. Please check.", "Error");
                                      });
                                  } else {
                                      duplicate.push(youTubeData.videoId);
                                      toastr.error("Video already exist with id - " + youTubeData.videoId, "Error");
                                  }
                              });
                          }
                      });
                  } else {
                      failed.push(funcName.values.id);
                      toastr.warning("No details found !!", "Warning");
                  }
              }).error(function (data, status, headers, config) { // called asynchronously if an error occurs or server returns response with an error status.
                  toastr.error("Youtube API failed to fetch data.", "Error");
              });
          }
  
  
     $scope.saveVideo = function () {
       //       var videoId = Youtube.getYoutubeParser($scope.form.url);
              var arrVid = []; // this is actually an array of 2K+ items.
              angular.forEach(arrVid, function (value, key) {
                  var videoId = value.replace("?v=", "");
                  Youtube.params.videoInfo.values.id = videoId;
                  $scope.getInfo(Youtube.params.videoInfo);
              });
              console.log("Failed Videos" + JSON.stringify(failed));
              console.log("Duplicate Videos" + JSON.stringify(duplicate));
          }
  </code></pre>