0

I have 2 functions in a class, both class getting data from API calls.

Here is the First function

getQuotes(){
    this.quoteService.getQuotes()
    .subscribe(
      quotes => {
        this.quotCode = this.quotes.BasicDetails[0].QuotCode;
        }
      });
}

Second Function

getOption(){
    this.quoteService.getOptions()
    .subscribe(
            options => {
     })
}

I want to get data from this line from first function

this.quotCode = this.quotes.BasicDetails[0].QuotCode;

and based on this.quotCode getOption() will have different params to pass and will get diff. response also. so it is necessary to use this.quotCode in second function

I'm calling getQuotes() in constuctor()

Can anyone please help me out? Thanks

1
  • @trichetriche can you please help here? Commented Jul 10, 2017 at 13:36

1 Answer 1

1

RXJS mergeMap is the operator you need : this way, you will execute the second request once the first one succeeds.

this.quoteService.getQuotes().mergeMap( quotes => {
    // Do whatever you need to do with quotes
    return this.quoteService.getOptions()
}).subscribe( options => {
    // Do whatever you need with options
});
Sign up to request clarification or add additional context in comments.

2 Comments

Okay,let me try
it works but sometime getOptions doesn't load at all even if first loads

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.