AngularJS-承诺之间的共享回报值
我正在向我的服务器发出一个获取请求,我获取响应,并将值存储在$scope.productIdAngularJS-承诺之间的共享回报值,angularjs,http,get,Angularjs,Http,Get,我正在向我的服务器发出一个获取请求,我获取响应,并将值存储在$scope.productId userService.get(true) .then(function(res) { $scope.productId = res.user.productid; } }); 然后我需要在另一个获取api请求中使用此值,以获取与此id相关的产品 apiService.get('/product/' + ???) .then(function(re
userService.get(true)
.then(function(res) {
$scope.productId = res.user.productid;
}
});
然后我需要在另一个获取api请求中使用此值,以获取与此id相关的产品
apiService.get('/product/' + ???)
.then(function(response) {
console.log(response)
})
.catch(function(response) {
});
我对承诺不熟悉,所以目标是将第一个请求的值传递给第二个请求 用这个
userService.get(true)
.then(function(res) {
$scope.productId = res.user.productid;
apiService.get('/product/' + ???)
.then(function(response) {
console.log(response)
})
.catch(function(response) {
});
}
});
执行第二个请求的代码没有访问
$scope
的权限?您好,弗兰克,没有,我没有为$scope
定义未定义的?或者对于$scope.productId
?未定义的$scope.productId,我可以控制台日志$scope。您可以演示如何发出这两个请求吗?因此,我们可以看到,一旦第一个请求实际完成,您是否正确地发出了第二个请求?您好,Aagam,谢谢您的帮助,您的解决方案可以工作,但我无法使其有效,因为我需要在外部访问$scope值。您可以在所有值到达该回调后进行回调。您可以使用$scope数据:)Aagam,非常感谢你的帮助,我会用另一种方式来做。再次感谢你