我创建了一个服务,它使用diff params进行不同的http调用。 的 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())
}
我在getOption()
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;
}
},
)
}
如果我getServiceWiseOptions()
getOptions()
getOption()
QuotType:
,我需要根据getServiceWiseOptions()
的回复从服务中致电getOptions()
和getOption()
上面的函数mergeMap()
有时可以工作,但有时它不会调用这些函数。
请给我一些建议我该怎么办?
我认为它与SELECT *
FROM daily_report
RIGHT JOIN (calendar c,user u) ON user_id=u.id AND date=c.datefield
WHERE c.datefield='2017-08-02' AND u.shall_create_every_day=1
答案 0 :(得分:1)
在getOption()
函数中,您使用this
表示您的回复,这使其成为控制器变量而不是response
数据,
所以将this.quotes
更改为quotes
getOption() {
this.quoteService.getQuotes().mergeMap( quotes => {
this.quotes = quotes; // this line if you want it to use anywhere else
if(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;
}
},
)
}