andresmijares
andresmijares

Reputation: 3744

sequential resolve, ui-router

If any way to resolve calls into a state but sequential? meaning, I need to resolve one and the other just after the first is done?

let's say my configuration looks like this:

 $stateProvider
   .state('home', {
      url : '/',
      resolve : {
         firstCall : function(myService) {
             return myService.getSomething();
         },
         secondCall : function(differentService, $q) {
             //$q.when(myService.getSomething).getOther();
             return differentService.getOther();
         }
      }//others parameters are omited
   }

this is bad and I know it, but I've never done something similar into the resolve of the router.

Any guessing?

Upvotes: 0

Views: 268

Answers (1)

georgeawg
georgeawg

Reputation: 48968

Chain the two calls.

$stateProvider
   .state('home', {
      url : '/',
      resolve : {
         bothCalls : function(myService) {
             return myService.getSomething()
                 .then (function (result) {
                      var promise = differentService.getOther();
                      return $q.all([result, promise]);
                 });
         },
      }//others parameters are omited
   }

The $q service waits for the getSomething call to resolve before initiating the getOther call. The final result is an array with both results.

Upvotes: 2

Related Questions