I developed a service that performs various http calls with different parameters. quote.service.ts
getQuotes(){
let params = {
"Type": "BasicDetail",
}
return this.http.post(this.url,params)
.map(res => res.json())
}
getOptions(){
let params = {
"Type": "Hoteloption",
}
return this.http.post(this.url,params)
.map(res=>res.json())
}
getServiceWiseOptions(){
let params = {
"Type": "ServiceWiseOption",
}
return this.http.post(this.url,params)
.map(res => res.json())
}
In my component code, I invoke the getOption()
within the constructor
.
component.ts
getOption() {
this.quoteService.getQuotes().mergeMap( quotes => {
if(this.quotes.BasicDetails[0].QuotType == 'QUOTTYP-3'){
return this.quoteService.getServiceWiseOptions()
}
else{
return this.quoteService.getOptions()
}
})
.subscribe(
options => {
this.optionsdata = options.resultData;
if(this.quotes.BasicDetails[0].QuotType == 'QUOTTYP-3'){
this.servicewiseData = options.resultData.ServiceWiseOption;
}else{
this.servicewiseData = options.resultData.Hoteloption;
}
},
)
}
The requirement is to call either getServiceWiseOptions()
or getOptions()
from the service based on the response of getOption()
. If the QuotType:
matches, then call getServiceWiseOptions()
; otherwise, call getOptions()
.
Although the function getOption()
works sometimes, it fails to call either of these functions at times.
I need suggestions on what steps to take next. I suspect it might be an issue with the mergeMap()
.