0

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

CuriousCoder
  • 11
  • 1
  • 2
  • Refer to this StackOverflow link. [Refer to this link](https://stackoverflow.com/questions/53767806/make-nested-http-calls-from-a-service-class-and-return-observable) – Meet Feb 19 '23 at 05:16

1 Answers1

1

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

Sameh
  • 1,318
  • 11
  • 11