I need to check when the "for loop" function has finished for all $http requests processing and can refresh the data grid, once and for all. Currently, the refresh happens for every $http request, which is not desired behaviour.
Have read a little about angularjs $q.all, but not sure of implementation in the scenario below.
Any help / advise is greatly appreciated. Thanks in advance.
Here is the snippet -
function chainedAjax(param1, param2) {
var something = something;
$http({
// processing
}).then(function(responseData) {
// processing
return $http({
// processing
});
}, function(ex) {
// error
}).then(function(responseData) {
// processing
return $http({
// processing
});
}, function(ex) {
// error
}).then(function(responseData) {
// success - Done
finish();
}, function(ex) {
// error
});
}
function init(selectedDocs) {
var something = something;
angular.forEach(selectedDocs, function(item, arrayIndex) {
chainedAjax(item.param1, item.param2);
});
}
function finish() {
refreshDocsTable(); // refreshes the current grid
}
init(selectedItems); // call init function