即时做出2个请求,但是当我从结果中得到的值,如果我调用变量之外的变量,它会得到空值,但因为我依赖2个不同的promisses最需要的结果,我也需要根据每个承诺的结果执行功能,我不知道如何解决它。2 promisses一起返回null
我的代码控制器:
$scope.originLatLong = null;
$scope.destinationLatLong = null;
//Get LAT and LONG from origin and destionation http://something/{Code}
$http.get('something/getLatLng/'+$scope.originAirport).then(function(response){
$scope.originLatLong = response.data; //doesnt return null
});
$http.get('something/'+$scope.destinationAirport).then(function(response){
$scope.destinationLatLong = response.data; //doesnt return null
});
console.log($scope.originLatLong) //returns null
console.log($scope.destinationLatLong) //returns null
var distanceTotal = calculate($scope.destinationLatLong,$scope.originLatLong);
谢谢Fissio,你能告诉我我做错了什么或为什么没有工作? – Pedro
你好,我做了一个console.log(distanceTotal)在承诺之外,没有任何显示,给了我一个未定义的“ – Pedro
检查我的编辑;问题可能是一样的,你需要使用'distanceTotal'内的代码' 。然后()'。 – Fissio