2016-11-09 43 views
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; 
      } 
     }); 
    }; 
}]); 
+0

這個console.log('Entra'+ $ scope.username);是發生兩次,還是隻發生在第二次?如果它只有第二次告訴我們誰叫你的功能.... –

+0

只在第一次。 – Bibliotec

+0

我有一個$ stateChangeStart事件,在切換頁面時檢查用戶的身份驗證 – Bibliotec

回答

0

我需要做一個$ $的範圍適用於()右地點變更後,並調用替換()讓角知道,事情發生了變化。

謝謝。

相關問題