我有這兩種后端呼叫方法。當我嘗試除錯這些時,在從isExisting方法獲得回應后
updateDocumentHttp方法正在呼叫,但沒有得到回應,控制元件就消失了。我有什么問題嗎,或者有沒有更好的解決方案?
this.dataService.processUpdateDocument(isExistingUrl, isExistingCriteria).subscribe();
@Injectable()
export class DataService {
processUpdateDocument(httpMethod, baseUrl, doc):Observable<any> {
if (httpMethod == 'POST') {
return this.isExisting(isExistingUrl, isExistingCriteria);
} else {
return this.updateDocumentHttp(httpMethod, baseUrl, doc);
}
}
isExisting(isExistingUrl, isExistingCriteria): Observable<any>{
return this.http.post(isExistingUrl, isExistingCriteria)
.pipe(map((response:[]) =>{
console.log("Already exist Result: " response.length);
if (response.length <= 0) {
return this.updateDocumentHttp(httpMethod, baseUrl, doc, options, domainToUpdate, callback, messages)
}
}
updateDocumentHttp(httpMethod, baseUrl, doc):Observable<any> {
return this.http.request<IApiResponse>(httpMethod, baseUrl, {
body: doc,
responseType: "json"
}).pipe(map(
data => {
console.log("Created / Updated : Successfully");
if (!domainToUpdate) {
app.childScope["domain"] = data;
}
return true;
}
)
});
}
}
uj5u.com熱心網友回復:
如果您不訂閱 Observables,它們將不會執行。在這個例子中,isExisting 方法的回傳型別是另一個需要訂閱的 observable,所以如果你使用下面的代碼,它會正常作業:
this.dataService.isExisting(isExistingUrl, isExistingCriteria)
.subscribe(result => result.subscribe());
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/512290.html
標籤:有角度的http
