angularjs - AngularJS - 在承诺之间共享返回值
问题描述
我正在向我的服务器发出get 请求,我得到响应并将值存储在$scope.productId 中
userService.get(true)
.then(function(res) {
$scope.productId = res.user.productid;
}
});
然后我需要在对 api 的另一个get 请求中使用这个值来获取与这个 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) {
});
}
});
推荐阅读
- reactjs - 警告:使用 `defaultValue` 或 `value` 道具
- python - 在使用 Selenium 的 Web 自动化过程中加载带有 PyQt5 冻结问题的动画
- mql4 - MQL4 EA 忽略一些箭头
- javascript - Socket.io 为 `on` 侦听器提供多个处理程序,如 Express
- php - PHP + SQL - 尝试从多个用户检索 ID。(逗号分隔)
- python - 使用 groupby 和 max(date) 在 pands 中创建新列
- typescript - 如何在 TypeScript 的界面中添加/覆盖属性?
- android - 我可以离线使用 Android SDK 文档吗?
- c++ - 套接字总是返回 INVALID_SOCKET
- javascript - 在方法内预取 Nuxt.js/Vue.js(表单完成后预取下一页)