我需要执行两个$http.get
调用,并且我需要将返回的响应数据发送到我的服务以进行进一步的计算。
我想要像下面这样做:
function productCalculationCtrl($scope, $http, MyService){
$scope.calculate = function(query){
$http.get('FIRSTRESTURL', {cache: false}).success(function(data){
$scope.product_list_1 = data;
});
$http.get('SECONDRESTURL', {'cache': false}).success(function(data){
$scope.product_list_2 = data;
});
$scope.results = MyService.doCalculation($scope.product_list_1, $scope.product_list_2);
}
}
在我的标记中,我将其称为
<button class="btn" ng-click="calculate(query)">Calculate</button>
$http.get
是异步的,所以当我传递给 doCalculation
方法时,我没有得到数据。
有什么办法可以实现多个 $http.get
请求,并像以上实现一样将两个响应数据都传递到服务中吗?