我们需要在typescript中调用返回类型为void的方法,但是类型脚本不应该继续下一行代码,直到void方法执行完成。我们怎样才能做到这一点。
在下面的示例中,我们必须从closeWindow调用saveEventDetails,但在关闭窗口中var win = window.open(" about:blank"," _self"); win.close();在saveEventDetails方法执行完成之前不应该执行。
EX: -
saveEventDetails(buttonClick: string = "") {
this.eventForm.markAsUntouched(false);
this.eventForm.value.claimNumber = this.appContext.claimNumber;
this.eventsService.patch(this.eventForm.value).subscribe(res => {
this.loadUserTrackingDetails();
this.userTrackingService.saveUserTrackingDetails(this.userTrackingModel).subscribe(r => {
if (buttonClick == "") {
this.showSuccess();
}
return Observable.of();
});
}, (errResp: any) => {
this.errorMessage = "Unable to load EVENT, invalid user or claim number";
return Observable.of();
});
}
closeWindow() {
this.eventForm.value.cmResidentStateLicensed = false;
Observable.create((observer: Observer<any>) => {
this.saveEventDetails("popup")
var v = true;
})
.subscribe(data => {
var win = window.open("about:blank", "_self");
win.close();
},
(errResp: any) => {
this.errorMessage = "Unable to Save EVENT, Please try after soemtime";
});
}
答案 0 :(得分:0)
为什么你不订阅saveEventDetails()返回的Observable?
closeWindow() {
this.eventForm.value.cmResidentStateLicensed = false;
this.saveEventDetails("popup").subscribe(data => {
var v = true;
var win = window.open("about:blank", "_self");
win.close();
},
(errResp: any) => {
this.errorMessage = "Unable to Save EVENT, Please try after soemtime";
});
}