(function () {
angular.module("Hawking").controller('loginController', function ($log, $scope, validateUser) {
var dataUser = { email: "[email protected]", senha: "123456" };
validateUser.getUser(dataUser).then(function(data){
console.log(data); // ok!
$scope.data = data;
});
console.log($scope.data); // undefined
})
.factory('validateUser', function ($http, $q) {
return {
getUser: function (userInfo) {
var deferred = $q.defer();
var status = {
id_usuario: null,
permission: false
};
$http.get('/hawkingBE/api/usuarios/').then(function (response) {
angular.forEach(response.data, function (value, key) {
if (value.email == userInfo.email && value.senha == userInfo.senha) {
status = {
id_usuario: value.id_usuario,
permission: true
}
}
});
});
deferred.resolve(status);
return deferred.promise;
}
}
});
})();