diff 매개 변수가있는 다른 http 호출이있는 서비스를 만들었습니다. quote.service.tsAngular2 HTTP 요청은 다른 응답에서 반환 된 데이터에 따라 달라집니다.
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())
}
내가 constructor
component.ts 내가 getServiceWiseOptions()
및 getOptions()
를 호출하는 것입니다 무엇이 필요
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;
}
},
)
}
내 구성 요소 코드에 getOption()
아래 전화을 받으면 getOption()
의 응답을 기반으로 한 서비스에서getServiceWiseOptions()
그렇지 않으면 getOptions()
.
위의 함수 getOption()
은 때때로 작동하지만 때때로이 함수 중 하나를 호출하지 않습니다.
제게 어떻게해야합니까? 나는 당신의 getOption()
기능에 mergeMap()
에
this.quotes
을 변경 그것을 대신response
데이터의 제어 변수하게this
와 응답,을 reffered 생각할 수 당신은'getQuotes()'메소드의 응답을 보낸다.'map'의'mergeMap' instaead를 사용하는 큰 이유가 있을까요? – Sravan
@Sravan 'mergeMap()'을 사용할 특별한 이유가 없습니다. 나는 누군가가 저에게 그렇게했다고 말했지만 그것에 대해서는 잘 모르겠다. 그것은 잘 작동하지 않는다. –
@Sravan 'mergeMap' 오류를 얻지 않으면 현재 코드에 따라'Property 'resultData'type에 존재하지 않는다 'Observable '' –