Here's the function I am working with:
this.getBenchmarkData = function () {
var benchmarkData = [];
var d = $q.defer();
users.forEach(function(user){
var dataArray = [];
modules.forEach(function (module) {
$http.get(api.getUrl('teamUserBenchmark', [user.user_id, module.id, user.team_id]))
.success(function (response) {
response.forEach(function(result){
dataArray.push(result.score);
})
});
});
benchmarkData.push(dataArray);
});
d.resolve(benchmarkData);
return d.promise
}
The issue is that d.resolve(benchmarkData)
runs before any actual data has been added to it.
I understand that this problem stems from the asynchronous $http
task. However, I'm unsure about how to go about resolving it. Can someone provide guidance on the correct approach?