1

I am trying to build a simple authentication using angular, it gives this error when making a ajax service call. Here is the code.

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 Answers 2

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.

Just remove it: $scope.login = function() {...}

Sign up to request clarification or add additional context in comments.

1 Comment

you beat me by 28 seconds :p
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.

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;
    }
  });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.