我想在同一的另一个地方使用
但是当尝试时:$http.get
的reponse.data
(JSON数据) Controller
$http({
method:"post",
url:"php/home/item.php/?proc=3",
data:{
'item_id':json[i].item_id
}
}).then(function (response) {
$scope.data = response.data; // or $rootScope
$scope.data = response.data;
console.log("after get response : "+$scope.data.length);
});
console.log("befor get response : "+$scope.data.length); // undefined
如何在收到 $http.get
的响应
后推迟一些指令
最佳答案
您传递给 then
的函数是您将执行推迟到收到响应之后的方式。这不仅仅是代码中的范围或位置问题,还是时间问题。您可以从该响应函数中调用其他函数,并传递响应——这是您可以从 Controller 中的其他位置访问响应并确保在收到响应后执行代码的唯一方法。
关于javascript - 如何在其他地方使用 $http.get 的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49722590/