Skip to content

Instantly share code, notes, and snippets.

@eabreusantos
Created October 19, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eabreusantos/cdd1b24acc9c0e3547a36368a17b29b6 to your computer and use it in GitHub Desktop.
Save eabreusantos/cdd1b24acc9c0e3547a36368a17b29b6 to your computer and use it in GitHub Desktop.
Example AngularJs Service
//Servico
app.factory('AuthService', function() {
return {
autenticar: AutenticarUsuario
};
//Autentica Usuário
function AutenticarUsuario(usuarios) {
return $http.post("/usuarioLogadoPermissoes", usuarios);
}
});
//Controller
app.controller("loginController", function($scope, $http, $location, AuthService){
$scope.usuarios = {};
$scope.autenticar = function() {
AuthService
.autenticar($scope.usuarios)
.then(function(response) {
$scope.usuarios = response.data;
var jsonAux = JSON.stringify(response.data);
localStorage.setItem("usuarioLogado",jsonAux);
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment