0
我在Angularjs中有一個登錄函數,它只在我第二次提交時纔有效。如何解決它?AngularJS - 如何在第一次提交進行身份驗證?
這是代碼:
.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;
}
});
};
}]);
這個console.log('Entra'+ $ scope.username);是發生兩次,還是隻發生在第二次?如果它只有第二次告訴我們誰叫你的功能.... –
只在第一次。 – Bibliotec
我有一個$ stateChangeStart事件,在切換頁面時檢查用戶的身份驗證 – Bibliotec