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