I have many $http
requests as following:
Scholarship.loadMaxAcademicYear().success(function (AcademicYearId) {
if (AcademicYearId) {
Scholarship.deleteAllCurrentData(data).success(function () {
Scholarship.copyDataToCurrentYear().success(function(){
Scholarship.getPromises(null, AcademicYearId).then(function () {
$scope.isSuccess = true;
$timeout(function () {
$scope.isSuccess = false;
$scope.isSubmit = false;
$scope.confirmModal.close();
}, 5000);
}, function(err){
importError();
});
}).error(function(){
importError();
})
}).error(function(){
importError();
});
}
}).error(function (err) {
importError();
});
I want to reduce the error callback to be only one at the end as following:
Scholarship.loadMaxAcademicYear().success(function (AcademicYearId) {
if (AcademicYearId) {
Scholarship.deleteAllCurrentData(data).success(function () {
Scholarship.copyDataToCurrentYear().success(function(){
Scholarship.getPromises(null, AcademicYearId).then(function () {
$scope.isSuccess = true;
$timeout(function () {
$scope.isSuccess = false;
$scope.isSubmit = false;
$scope.confirmModal.close();
}, 5000);
}
})
})
}
}).error(function (err) {
importError();
});
I'm thinking of using the async but Angular might have some way to handle this kind of problem. Would it be possible to do so in AngularJs?