Josip Ivković
Josip Ivković

Reputation: 37

multiple $http.get not working

Having issues bringing in multiple data from API endpoints. Results come back undefined for values in $q.all method

$http.get('url').success(function(data, status, headers, config) {
        $scope.data1= data;
    })
    $http.get('url').success(function(data, status, headers, config) {
        $scope.data2= data;
    })
    $http.get('url').success(function(data, status, headers, config) {
        $scope.data3= data;
    })
    $http.get('url').success(function(data, status, headers, config) {
        $scope.data4= data;
    })



    $q.all([$scope.data1, $scope.data2, $scope.data3, $scope.data4]).then(function(values) {
        $scope.data= values;
    });

Upvotes: 0

Views: 88

Answers (1)

rob
rob

Reputation: 18513

$q.all takes an array of promises so you'd have to do something like this.

$scope.promise1 = $http.get('url');
$scope.promise2 = $http.get('url');
$scope.promise3 = $http.get('url');
$scope.promise4 = $http.get('url');

$q.all([$scope.promise1, $scope.promise2, $scope.promise3, $scope.promise4]).then(function (values) {
    $scope.data = values;
});

Upvotes: 3

Related Questions