私は2つの要求をしているが、私は結果から値を得る場合は、私は2つの異なる約束のrequrest結果に依存するので、それぞれの約束の結果に基づいて機能を実行する私はどのように私はそれを解決することができないのか分からない。 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);
ありがとうございました。私が間違っていたこと、またはなぜ失敗したのか教えていただけますか? – Pedro
こんにちは、私はpromiseの外でconsole.log(distanceTotal)を作って何も表示せず、私に未定義を与えました。 " – Pedro
私の編集をチェックしてください;問題は同じでしょう。' distanceTotal'を使用して、 .then() '。 – Fissio