I have a service in the angle and wanted to make a forEach to retrieve the value of the user, to authenticate the login
My service:
.service('usuariosService', function ($rootScope, $location,$http) {
this.validaLogin = function(user){
var usuarios = [];
$http.get('api/user').then(function(resultado){
usuarios = resultado.data;
});
angular.forEach(usuarios, function(value, index){
if(value.nome == user.username){
$rootScope.usuarioLogado = value;
}else{
console.log('Não é igual');
}
})
}
})
But I can not do this forEach, I can never buy the values, I do not know if it's the api return, or the value.name is not getting any value.
My json returns this:
[{ "nome" : "teste", "password" : "teste" },
{ "nome" : "teste1", "password" : "teste1" }];
Can anyone help?