In a controller, I have two HTTP requests:
function findProfessionalEmail(professional) {
EmailHunter.findProfessionalEmail(professional.company_name, professional.first_name,
professionalLastName).then(function (data) {
var score = data.data.data.score;
if (isProfessionalEmailScoreHigh(score)) {
vm.professional.email = data.data.data.email;
}
});
}
and
function checkAvailability(professional, callback) {
findProfessionalEmail(professional);
var cb = callback || angular.noop;
CheckAvailability.save(getCheckAvailabilityDTO(vm.professional), function () {
console.log('Success!');
return cb();
}, function (err) {
console.log('Erro!');
return cb(err);
}).$promise;
}
When invoking the second "checkAvailability ()" method, the system does not execute my request for the "findProfessionalEmail ()" method first, and always executes the "checkAvailability ()" request first.
Why this behavior? How can I fix it?