Understanding the use of promises in Angular for handling async operations is crucial, but I'm struggling to implement it effectively in this scenario.
function fetchLineGraphData(promises){
var dataPoints = [];
for (var i = 0; i < promises.length; i++) {
$http.get('/file/tsDataPoints/'+promises[i].unit+"?startDate="+promises[i].startTs+"&endDate="+promises[i].endTs+"&startState="+promises[i].startState+"&endState="+promises[i].endState).success(function(data){
dataPoints.push(data);
console.log(data);
});
}
console.log(dataPoints);
return dataPoints;
}
The challenge lies in dealing with an array of data to construct multiple queries instead of just one. How should I approach this? Any concrete examples or guidance would be greatly appreciated. Thank you.