I've got 2 factory functions:
Factories
factory.getCurrEmployee = function()
{
data = {"api_token": authenticationFactory.getToken()};
url = GLOBALS.url + 'show/employee/' + $cookieStore.get('employeeid');
return requestFactory.post(url, data)
.then(function (response) {
return response.data.result.Employee;
}, function () {
$window.location.assign('/');
});
}
factory.isSuperadministrator = function() {
factory.getCurrEmployee().then(function (employee) {
if(employee.Role == 'Superadministrator')
{
return true; //console.log('Superadministrator') <- that console.log is visible in my console
}
return false;
});
}
return factory;
In my controller I would expect true or false (a user is a Superadministrator or not) but the result is nothing. If I console.log in my factory.isSuperadministrator the result is true.
Controller
console.log(employeeFactory.isSuperadministrator());
Why is this not working?
Booleanvalue's will never get returned untill, promise gets returned. becausebooleanhas been return from callback function..thenin his calling controller code but is returning the expected value in the service callback shows an underlying lack of knowledge on how promise chaining works. Which is why i said he's returning a promise not the value in his callback.