I am trying to use $q.all in the code below. But I think I've misunderstood some key ideas because it's not working as I expected. If anyone could give me some pointers that would be really appreciated.
The issue is in $q.all(toSend.pie.slices).then()
:
var someData = {...};
var toSend = {
pie: {
slices: []
}
};
toSend.pie.slices = generatePieSlice(someData);
$q.all(toSend.pie.slices).then(function(data){
if(data) {
console.log(data); // this is undefined :(
//do something else
}
});
function generatePieSlice(data) {
var arr = [];
if(data) {
angular.forEach(data, function(resp_o, resp_n){
arr.push({
name: resp_o.display,
marketValue: resp_o.value,
percentage: resp_o.percentage,
key: resp_n
});
});
}
$q.all(arr).then(function(data) {
if(data) {
console.log(data); // this gives me with the correct data
return data;
}
});
}