角度 6 中的嵌套 http 调用

发布于 2025-01-20 05:09:44 字数 635 浏览 2 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红墙和绿瓦 2025-01-27 05:09:44

您是否尝试使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文