When working with the API, I need to load three different things:
- users
- groups
- messages
Currently, my approach involves using $q.all() to load all three at once:
var loadAll = $q.all([
getUsers.all(),
getGroups.all(),
getMessages.all()
]);
loadAll.then(function (data) {
$scope.users = data[0];
$scope.groups = data[1];
$scope.messages = data[2];
};
Although this works, it doesn't load them in the specific order I want. I'd like to first load users, then groups, and finally messages.
I'm having trouble figuring out how to achieve this correctly...
The services return promises like so:
getUsers.all()
.then(function(data) {
$scope.users = data;
};
But when I try chaining the promises together, they resolve as soon as users are loaded without waiting for others:
getUsers.all()
.then(function(data) {
$scope.users = data;
getGroups.all()
.then(function(data) {
// etc...
}
};
How can I ensure that the API calls are made in the desired order?