AngularJS - collecting multiple receive requests into a json array, and then going to the directive

I am new to angular and struggling how to solve my problem.

I need to access the API several times for user data, store everything as a JSON array, and when all the data is collected (all results as one array), I need to pass it to a directive that will use it for visualization (e.g. d3.js-pie chart).

$scope.allData = [];

$http.get("****link here****/students")
    .success(function (data) {
        students = data;

        for (i = 0; i < students.length; i = i + 1) {

            $http.get("**** link here ****/quest/" + students[i].id)
                .success(function (data) {
                    quest = data;

         $scope.allData.push({
                            id: quest.id,
                            value: quest.length
                        });
           }
        }

and then pass it to the directive as

   <bar-chart data='allData'></bar-chart>

even if I set the clock in the directive and have scope as the '=' directive gets an empty array.

In my other code, when I just make one http get call for the json array, I can easily pass it to the directive and it works fine.


EDIT1:

OK, so now I use the premises, but still the allData array is 0. Even with a simple example:

 $scope.allData = [];
 var promieses = [];
 for (i = 0; i < 10; i = i + 1) {

            promieses.push($http.get("***link***/student/" + students[i].id));
}

$q.all(promieses).then(function (data) {
    for (i = 0; i < data.length; i = i + 1) {
        $scope.allData.push("test");
    }
});

html {{allData]]//0

+4
1

, $q. promises, $q.all. Combines multiple promises into a single promise that is resolved when all of the input promises are resolved.

. :

students = data;
var promises = [];
for (i = 0; i < students.length; i = i + 1) {

    promises.push($http.get("**** link here ****/quest/" + students[i].id));

}

$q.all(promises).then(function(response) {
    for (var i = 0; i < response.length; i++) {
         $scope.allData.push({
             id: response[i].data.id,
             value: response[i].data.length
         });
    }
})

: http://plnkr.co/edit/TF2pAnIkWquX1Y4aHExG?p=preview

+2

Source: https://habr.com/ru/post/1568941/