【发布时间】:2013-06-06 07:18:27
【问题描述】:
我需要进行两次$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 请求并像上述实现一样工作以将响应数据传递到服务中吗?
【问题讨论】:
-
我认为你可以链接承诺