Created
October 19, 2017 13:33
-
-
Save eabreusantos/cdd1b24acc9c0e3547a36368a17b29b6 to your computer and use it in GitHub Desktop.
Example AngularJs Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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