$ionicLoading waiting for multiple processes

Hi all, I have a refresh function that makes two separate remote API calls

$scope.refreshAll(){
  $scope.refreshSomething();
  $scope.refreshSomethingElse();
}

I would like to perform $ionicLoading.show(); before th first call and then do $ionicLoading.hide(); when both responses are complete.

I assume there is a really elegant way for doing such a thing, but being new to Ionic/AngularJS, I can’t get my head around it yet.

Is anyone able to offer any input, or link me to a relevant article for such a thing?

Cheers!
Chris

It shoud be like this.

$scope.refreshAll() = function(){

    $ionicLoading.show();

    $q.all([
        $scope.refreshSomething(),
        $scope.refreshSomethingElse()
    ]).then(function(responses){
        // handling responses here

         $ionicLoading.hide();
    });
};

This require AngularJs Promises $q. Remember that $scope.refreshSomething() and $scope.refreshSomethingElse() must return promise .

2 Likes

Thank you so much :smile:

I’ve seen the mention of $q before, but was never able to quite get my head around it. Your example not only gives me exactly what I want, but it’s a brilliant example of what $q can be used for.

Thanks once again!
-Chris

You’re welcome… glad to help :smile: