I am currently utilizing a service that has the capability to fetch data for all dashboards within my system.
.service('dashboardServices', function ($http, $q) {
return {
getData: getData
}
//defining promises and their respective http request URLs
var promise01 = $http({method: 'GET', url: urlpromise01, cache: false});
var promise02 = $http({method: 'GET', url: urlpromise02, cache: false});
var promise03 = $http({method: 'GET', url: urlpromise03, cache: false});
function getData(){
var promises = [];
var promises = $q.all([promise01, promise02, promise03])
.then(function(data){
setDashboardData(data[0].data);
setDashboardData(data[1].data);
setDynamicDashboardData(data[2].data);
})
return promises;
}
})
Within my controller, I am using this service to trigger a modal window with a loading message while fetching data from the server.
.controller('MainCtrl', function($state, $scope, $ionicModal, dashboardServices) {
$ionicModal.fromTemplateUrl('views/loading.html', {
scope: $scope,
backdropClickToClose: false,
hardwareBackButtonClose: true,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show().then(function() {
dashboardServices.getData().then(function() {
$scope.closeModal();
})
})
}
$scope.closeModal = function() {
$scope.modal.hide();
};
})
I am now seeking a way to display an appropriate message if the requests fail, as the loading modal window remains open in case of failures. I cannot use .error(function()... in my controller due to the restriction that .then().... .error() is not supported for $q.all. Is there a possible implementation for handling such exceptions?