O serviço AngularJS retorna indefinido
Eu tenho o seguinte serviço:
app.services.emailService = ['$http', '$sce', function ($http, $sce) {
return {
getMessage: function(messageId, callback) {
$http.get('/api/email/inbox' + '/' + messageId).then(function(response) {
response.data.message.updated_at = new Date(response.data.message.updated_at.replace(/-/g,"/"));
response.data.message.body = $sce.trustAsHtml(response.data.message.body);
return response.data;
});
}
};
}];
No meu controlador, estou atribuindo o valor de retorno a um$scope.message
var para que eu possa exibir no front end.
$scope.message
é indefinido
$scope.getMessage = function(messageId) {
$scope.message = emailService.getMessage($scope.messages[messageId].id);
console.log($scope.message);
}