Reputation: 3744
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
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