2015-04-03 61 views
1

我想使用角度來構建一個簡單的認證,它使ajax服務調用時出現此錯誤。這是代碼。無法讀取與角度未定義的屬性'獲得'

代碼

mainModule.controller("loginController", ['$scope', '$http', '$rootScope', '$presence', '$apps', '$helpers', 
    function($scope, $http, $rootScope, $presence, $apps, $helpers) { 
     $scope.currentUser; 
     $scope.password; 
     $rootScope.url = "http://localhost:53455/eSuperVision.svc"; 
     $scope.login = function($scope, $http) { 
      $http.get($rootScope.url + "/login/" + $scope.currentUser + "/" + $scope.password).success(function(response) { 
       if (response == true) { 
        location.href = "home.html"; 
       } else { 
        $("#loginDialog").effect("shake"); 
        $scope.showError = true; 
       } 
      }); 
     } 
    } 
]); 

回答

2

因爲$ HTTP使用的是在您的登錄功能不會在控制器注入的$ http服務,但傳遞給函數的任意PARAM。

只是將其刪除:$ scope.login =函數(){...}

+0

您28秒打我:P – 2015-04-03 11:59:46

1

你的功能不應該通過的$http & $scope參數,之後就被通過函數重載和他們都得到了不確定。你應該使用從控制器注入的依賴關係。

代碼

$scope.login = function() { 
    $http.get($rootScope.url + "/login/" + $scope.currentUser + "/" + $scope.password).success(function(response) { 
    if (response == true) { 
     location.href = "home.html"; 
    } else { 
     $("#loginDialog").effect("shake"); 
     $scope.showError = true; 
    } 
    }); 
} 
相關問題