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

1
  • Refer to this StackOverflow link. Refer to this link Commented Feb 19, 2023 at 5:16

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.