Angularjs multiple $http.get request

前端 未结 3 1760
渐次进展
渐次进展 2021-01-29 23:35

I need to do two $http.get call and I need to send returned response data to my service for doing further calculation.

I want to do something like below:

3条回答
  •  天涯浪人
    2021-01-30 00:16

    What you need is $q.all.

    Add $q to controller's dependencies, then try:

    $scope.product_list_1 = $http.get('FIRSTRESTURL', {cache: false});
    $scope.product_list_2 = $http.get('SECONDRESTURL', {'cache': false});
    
    $q.all([$scope.product_list_1, $scope.product_list_2]).then(function(values) {
        $scope.results = MyService.doCalculation(values[0], values[1]);
    });
    

提交回复
热议问题