i am trying to monitor a close event for a tab opened by window.open() using setInterval(). when I tried to clearInterval in ngOnDestroy() it alway telling me the timmer is undefined. An suggestions?
timmer: any;
newWindow: any;
ngOnDestroy() {
this.newWindow.close(); // newWindow is always undefined...
clearInterval(this.timmer) // timmer is always undefined...
}
// this I am calling an api to get the new window url and use window.open to open it...
public openWindow() {
this.claimsService.getUrl(this.id).subscribe(
response => {
this.newWindow = window.open(response.url);
this.timmer = setInterval(() => {
if (newWindow.closed) {
clearInterval(loop);
}
},
error => {
//...error handler...
}
);
}