我的 Angular Controller 中有一个代码
$scope.message = '';
$http.post('/save/').success(function(data) {
$scope.message = "success";
});
console.log($scope.message);
//get empty string?
为什么我运行后,$scope.message 上出现空字符串? http.post 成功时如何返回值,因为我想为我的另一个函数重用该值。不管怎样,谢谢。
最佳答案
您正在寻找的是这样的:
$scope.$watch("message", function(value){
console.log($scope.message);
});
这里是a sample plnkr example我已经做了
关于http - Angular 如何从 http.post 成功返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14580667/