0
Ich habe eine Login-Funktion in Angularjs, es funktioniert nur, wenn ich es zum zweiten Mal einreiche. Wie man es löst?AngularJS - Wie authentifiziere ich mich bei der ersten Einreichung?
Dies ist der Code.
.controller('LoginCtrl',
['$scope', '$rootScope', '$location', 'AuthenticationService',
function ($scope, $rootScope, $location, AuthenticationService) {
// reset login status
AuthenticationService.ClearCredentials();
$scope.login = function() {
$scope.dataLoading = true;
console.log('Entra '+$scope.username);
AuthenticationService.Login($scope.username, $scope.password, function(response) {
if(response.success) {
AuthenticationService.SetCredentials($scope.username, $scope.password, $rootScope.datos.grupo);
$location.path('/');
console.log('Comprueba y redirecciona');
} else {
console.log('Falla');
$scope.error = response.message;
$scope.dataLoading = false;
}
});
};
}]);
Diese console.log ('Entra' + $ scope.username); passiert zweimal, oder nur zum zweiten Mal? Wenn es nur das zweite mal zeigt, wer deine Funktion aufruft .... –
Nur beim ersten Mal. – Bibliotec
Ich habe ein $ stateChangeStart-Ereignis, um die Benutzerauthentifizierung beim Seitenwechsel zu überprüfen – Bibliotec