We have a requirement to call a method of return type void, in typescript, but type script should not continue with the next line of code until void method executing is complete. How can we achieve this.
in the below example we have to call saveEventDetails from closeWindow, but in close window var win = window.open("about:blank", "_self"); win.close(); should not execute until saveEventDetails method execution is completed.
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";
});
}
;
at the end of the statement. There should bereturned
value. Alsoclose()
function doesn't work anyway you have to remove it.