AngularJS新手,想知道处理三个异步请求的正确方法是什么,其中第三个参数由前两个的响应定义。
two addresses are passed to this function
$scope.getRoutes = function(origin, destination) {
//1.A request is made to get the coordinates of the first address
dataFactory.geocode(origin)
.success(function(data) {
$scope.originObj = data;
})
.error(function () {
});
//2.Same for the second address
dataFactory.geocode(destination)
.success(function(data) {
$scope.destinationObj = data;
})
.error(function () {
});
//3.Finally a request for transport routes between the two sets of coordinates
dataFactory.getRoutes($scope.originObj.coordinates, $scope.destinationObj.coordinates)
.success(function(data) {
$scope.routes = data;
})
.error(function () {
});
};
这给了我错误:TypeError:无法读取undefined
的属性'coordinates'将请求嵌套在成功函数函数中,但有没有更好的方法让最后一个请求等待其他两个请求?