I am facing an issue while trying to fetch multiple data from $http inside _.each function and display the combined data in $scope.tasksData.
The problem I encountered is that _.each is being executed later, causing it to return null first. Can someone please provide guidance on how to resolve this issue?
Thank you
var tasksList, processingStageId;
var apiURL = "http://localhost:9080/caseDetails/" + $stateParams.caseId + "?_=1461046349867";
var stagesList = $http.get(apiURL).then(function(resdata, status, headers, config) {
return resdata;
}).then(function(stagesData) {
stageId = stagesData.data.childStages;
var allTasksData = [];
var self = this;
_.each(stageId, function(item) {
var stagesApiURL = "http://localhost:9080/stageDetails/" + item.stage.stageId;
$http.get(stagesApiURL).then(function(taskData, status, headers, config) {
//_.extend(allTasksData, taskData.data);
allTasksData.push(taskData.data);
});
});
return allTasksData;
}).then(function(allTasksData) {
console.log("Hello");
_.each(allTasksData, function(data) {
$scope.tasksData.concat(data);
});
});