I ran into a small dilemma. In this angularJs app (1.3.7v) I fetch requirements as well as user belongings from the server and perform some front-end validation. Which looks something like this:
validationFunction = function(userId){
return new Promise(function(resolve, reject){
Promise.all([
requirementService.requirementApi.requirements.getAll().$promise,
userBelongingsService.userBelongingsApi.getAll(userId).$promise
]).then(function(requirements,belongings){
console.log(requirements, belongings);
resolve(isValid(requirements, belongings));
}).catch(function (err) {
reject(err);
});
});
}
For reference I also tried
validationFunction = function(userId){
return new Promise(function(resolve, reject){
requirementService.requirementApi.requirements.getAll().$promise.then(function(requirements) {
return [requirements, userBelongingsService.userBelongingsApi.getAll(userId)];
}).then(function(requirements,belongings){
console.log(requirements, belongings);
resolve(isValid(requirements, belongings));
}).catch(function (err) {
reject(err);
});
});
}
The promises are async and so they only get resolved later. But if used with .then() it should wait until they are resolved (rejected or resolved). Although in both methods the promises are resolve(at some time) at the moment when they are passed to the function they are not. And so the function fails saying that they are undefined. So what is the other way or am I missing something? :)