title: Angular http post on loops
body: <p>I am trying to use angular http post inside a loop using angular forEach as advised here- <a href="https://stackoverflow.com/questions/24064976/angular-http-get-on-loop">Angular HTTP Get on loop</a> and <a href="https://stackoverflow.com/questions/21020360/angularjs-loop-trought-http-post">Angularjs loop trought $http.post</a> but the solution is not working in my case. The http post always returns result with respect to the last item in LifeBenefitTRAD but I want the result for each item in the loop. e.g. If I have 4 items in the list of LifeBenefitTRAD, my post method is executing 4 times but w.r.t the fourth item in the list.<img src="https://i.stack.imgur.com/eEWtD.png" alt="enter image description here"> The execution always happens with respect to last object.Please tell me what am I doing wrong here?-</p>
  
  <pre><code>   $scope.GenerateAllTradQuote = function () {
          var TRADPlanDetails = {};
          console.log(LifeBenefitTRAD);
          //for (var i = 0; i &lt; LifeBenefitTRAD.length; i++) {
          LifeBenefitTRAD.forEach(function (trad) {
             TRADPlanDetails.QuoteName = "TradQuote_" + trad.LifeBenefitValue;
             TRADPlanDetails.LifeBenefitId = trad.LifeBenefitId;
             TRADPlanDetails.LifeBenefitValue = trad.LifeBenefitValue;
  
              console.log(TRADPlanDetails);
  
              $http({
                  url: key_Url_GenerateTradQuote,
                  method: key_String_HttpPost,
                 // async: true,
                  params: TRADPlanDetails
              }).then(function (result) {
                  $scope.TRAD_PlanDetails.TRAD_DisplayFlag = true;
                  if (result.data != key_String_Zero) {
  
                      $scope.TRAD_PlanDetails.TRAD_DisplayMsg = key_Confirm_Successful_Quote;
                  }
                  else {
                      $scope.TRAD_PlanDetails.TRAD_DisplayMsg = key_Confirm_failed_Quote;
                  }
              });
          });
         // }
      };
  </code></pre>