In a function called loadData, there are 5 parallel ajax calls being made to set data in the resulrArray with different dataType and their respective counts.
When the dataCollection() method is invoked, I am getting different count results for different dataTypes due to these simultaneous calls (each call sets a unique data type value).
How can I properly handle object population when making parallel calls OR should parallel ajax calls not be allowed for the shared object?
Here is some sample code for clarification:
app.factory("appfactory",['$q',function($q) {
return {
loadData:function(){
return $q.all([this.f1(), this.f2(), this.f3(), this.f4(), this.f5()])
.then(function(response){
return response;
});
},
}
}]);
app.controller('appcontroller',['$scope','appfactory',function($scope, appfactory){
appfactory.dataCollection()
.then(function(response){
for(var i=0; i<len; i++){
var dataType = response.type;
var dataCount = response.count;
resulrArray.push({ "dataType":dataType, "dataCount":dataCount });
}
});
}]);