Nasreddin
Nasreddin

Reputation: 1647

AngularJS: console.log does not display anything

I wrote a controller for login page. Here is my controller:

var authApp = angular.module('loginApp', [])

authApp.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){
    $scope.authenticate = function() {
        loginFactory.login($scope.username, $scope.password)
        .then(function(response) {
            console.log(response.$statusText);
        }, function errorCallBack(response) {
            console.log(response.$statusText);
        });
    }

}]);

My service:

authApp.factory("loginFactory", function ($http) {
    return{
        login: function(username, password) {
            var data = "username="+username+"&password="+password+"&submit=Login";
            return $http({
                method: 'POST',
                url: 'http://localhost:8080/login',
                data: data,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                }
            });  
        }

When I debug the code, authentication seems successful and it did get into then function. However nothing displays in console. And I got a warning(?) saying undefined for the line console.log(response.$statusText);. It is not an error since it is not red. Why doesn't it print out anything?

Upvotes: 0

Views: 4568

Answers (1)

Cameron637
Cameron637

Reputation: 1719

Use response.statusText not response.$statusText. The documentation for AngularJS $http requests lists statusText as one of the properties of the response object - https://docs.angularjs.org/api/ng/service/$http

Upvotes: 2

Related Questions