我正在尝试使用setInterval()监视window.open()打开的选项卡的关闭事件。当我尝试在ngOnDestroy()中清除clearInterval时,它总是告诉我微调是未定义的。有建议吗?
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...
}
);
}