I am trying to build a simple authentication using angular, it gives this error when making a ajax service call. Here is the code.
我正在尝试使用角度构建一个简单的身份验证,它在进行ajax服务调用时产生了这个错误。这是代码。
Code
代码
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 个解决方案
#1
2
Because the $http you are using in your login fuction is not the $http service injected in the controller but an arbitrary param passed to the function.
因为您在登录函数中使用的$http不是注入到控制器中的$http服务,而是传递给函数的任意参数。
Just remove it: $scope.login = function() {...}
只是删除:$范围。登录= function(){…}
#2
1
You function should not pass arguments of $http
& $scope
, they are getting overridden by a function and both of them got undefined. you should use the dependency which you have injected from controller.
函数不应该传递$http和$scope的参数,它们被函数覆盖,它们都没有定义。您应该使用从controller注入的依赖项。
Code
代码
$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;
}
});
}
#1
2
Because the $http you are using in your login fuction is not the $http service injected in the controller but an arbitrary param passed to the function.
因为您在登录函数中使用的$http不是注入到控制器中的$http服务,而是传递给函数的任意参数。
Just remove it: $scope.login = function() {...}
只是删除:$范围。登录= function(){…}
#2
1
You function should not pass arguments of $http
& $scope
, they are getting overridden by a function and both of them got undefined. you should use the dependency which you have injected from controller.
函数不应该传递$http和$scope的参数,它们被函数覆盖,它们都没有定义。您应该使用从controller注入的依赖项。
Code
代码
$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;
}
});
}