nickg
nickg

Reputation: 151

Angular $http Promises and callbacks not firing

I'm trying to get a callback function to fire after an Angular $http Post but I'm having no luck. My Post function is working, but not the callback. I see on Angular's site that .success() has been deprecated so I'm trying .then() but that doesnt seem to do anything either.

Can anyone please tell me what I'm missing? Thank you very much in advance.

starwarsApp.controller('appController', ['$scope', '$http','$q', function($scope, $http,$q) { 

    $scope.addContact = function(){
        $http.post('/jediList',$scope.jediEntered).then(function(response){
            console.log('Why am I not being seen?');
        }); 
    };

}]);

Upvotes: 0

Views: 411

Answers (1)

nickg
nickg

Reputation: 151

Thank you to everyone who helped. OMG i just realized what's wrong. I never stopped the server connection in express with a 'res.end(), so the $http.post was never finishing to even call the callback. I've spent the last day agonizing over js promises only to realize this now.

So this code works fine. But for anyone having a similar issue, make sure your Node and/or Express connections are being ended with a res.end().

$scope.addContact = function(){
    $http.post('/jediList',$scope.jediEntered).then(function(response){
        console.log('NOW I am being seen!');
    }); 
};

Upvotes: 2

Related Questions