角度 6 中的嵌套 http 调用
我正在尝试在Angular 6中进行嵌套的HTTP呼叫工作。基本上,我试图通过一个循环迭代并进行两个服务器端呼叫,我想清除这两个响应中的数据。什么是最简单的方法?我下面的代码无法正常工作。
async search() {
const stockLists = ['GOOGL', 'FB', 'ABNB', 'LULU', 'CRM']
for await(const stock of stockLists) {
await this.apiservice.GetStockOverview(stock).subscribe(async data => {
await this.apiservice.GetCurrentStockData(stock).subscribe(currenStockdata => {
data.currentStockPrice = (currenStockdata['Global Quote']['05. price']);
this.stockDataOverview.push(data);
})
})
await this.sleep(12000);
}
}
注意 - 我在此处添加了计时器,因为我只能对此API拨打5个电话。
提前致谢
I am trying to make a nested Http call work in angular 6. Basically, i am trying to iterate through a for loop and make two server side calls, i want to purge the data from those two responses. Whats the easiest way to achieve this? My code below isn't working as expected.
async search() {
const stockLists = ['GOOGL', 'FB', 'ABNB', 'LULU', 'CRM']
for await(const stock of stockLists) {
await this.apiservice.GetStockOverview(stock).subscribe(async data => {
await this.apiservice.GetCurrentStockData(stock).subscribe(currenStockdata => {
data.currentStockPrice = (currenStockdata['Global Quote']['05. price']);
this.stockDataOverview.push(data);
})
})
await this.sleep(12000);
}
}
Note- i added the timer there because i can make only 5 calls per minute to this api.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试使用RXJS的叉
该URL示例解释了这一切,无论您需要发出并行请求还是顺序的请求,请读取它,希望您发现它有帮助
rxjs> rxjs两个http call
Have you tried to use forkJoin of RXJS
This Url sample explains it all whether you need to issue parallel requests or sequential ones, give it a good read and I hope you find it helpful
RxJS Two http Calls