2015-04-03 60 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; 
    } 
    }); 
} 
相关问题