Every time I check the console, I see the following:
- teamsUpdated2
- addUserToProjects
- deleteUserFromProjects
However, they should be displayed in a different order.
var result = teamService.addOrDeleteUser(userId, newTeams, deleteTeams);
result.then(function () {
console.log("teamsUpdated2");
});
A function that includes multiple promises:
var _addOrDeleteUser = function (userId, addToProjects, removeFromProjects) {
var deferred = $q.defer();
var promises = [];
promises.push(projectResource.addUserToProjects({ userId: userId }, addToProjects, function (result) {
console.log("addUserToProjects");
deferred.resolve();
return result;
}));
promises.push(projectResource.deleteUserFromProjects({ userId: userId }, removeFromProjects, function (result) {
console.log("deleteUserFromProjects");
deferred.resolve();
return result;
}));
return $q.all(promises);
}