Having some trouble with my implementation of $q.all in the code snippet below. It seems I may have misunderstood a few concepts as it's not functioning as expected. Would greatly appreciate any guidance or tips.
The specific problem lies within $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); // currently returning undefined :(
//perform additional actions
}
});
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); // correctly displaying the data
return data;
}
});
}