Angular $http 承诺和回调未触发
Angular $http Promises and callbacks not firing
我试图让回调函数在 Angular $http Post 之后触发,但我没有运气。我的 Post 功能正常,但回调无效。我在 Angular 的网站上看到 .success()
已被弃用,所以我正在尝试 .then()
但这似乎也没有任何作用。
谁能告诉我我错过了什么?非常感谢你提前。
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?');
});
};
}]);
感谢所有提供帮助的人。天哪,我才意识到出了什么问题。我从来没有用'res.end() 快速停止服务器连接,所以$http.post 从来没有完成甚至调用回调。我花了最后一天的时间为 js promises 而苦恼,现在才意识到这一点。
所以这段代码工作正常。但是对于遇到类似问题的任何人,请确保您的 Node and/or Express 连接以 res.end() 结束。
$scope.addContact = function(){
$http.post('/jediList',$scope.jediEntered).then(function(response){
console.log('NOW I am being seen!');
});
};
我试图让回调函数在 Angular $http Post 之后触发,但我没有运气。我的 Post 功能正常,但回调无效。我在 Angular 的网站上看到 .success()
已被弃用,所以我正在尝试 .then()
但这似乎也没有任何作用。
谁能告诉我我错过了什么?非常感谢你提前。
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?');
});
};
}]);
感谢所有提供帮助的人。天哪,我才意识到出了什么问题。我从来没有用'res.end() 快速停止服务器连接,所以$http.post 从来没有完成甚至调用回调。我花了最后一天的时间为 js promises 而苦恼,现在才意识到这一点。
所以这段代码工作正常。但是对于遇到类似问题的任何人,请确保您的 Node and/or Express 连接以 res.end() 结束。
$scope.addContact = function(){
$http.post('/jediList',$scope.jediEntered).then(function(response){
console.log('NOW I am being seen!');
});
};