Reputation: 2065
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
Upvotes: 0
Views: 805
Reputation: 1873
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
});
Upvotes: 1