尝试清除间隔时出错"timeout.close is not a function" - 角度(5)



当我清除间隔时出现此错误:

ERROR Error: Uncaught (in promise): TypeError: timeout.close is not a function
TypeError: timeout.close is not a function
    at exports.clearTimeout.exports.clearInterval (main.js:14)
    at LiveTestGraphComponent.ngOnDestroy

设置间隔功能:

this.inrvl = setInterval(() => loop(+new Date()), 5);

和销毁功能:

ngOnDestroy(): void {
    if (this.inrvl) clearInterval(this.inrvl)
}
组件

在父组件中使用 ngIf 销毁:

<test *ngIf="data.length" </test>

这是因为您的 IDE!确保您的 IDE 不包含自动导入,例如

import { clearInterval } from 'timers'; 

如果是这样,请将其删除。休息应该没问题。

clearTimeout也有同样的问题。

使用window.clearTimeout而不是clearTimeout也可以,以防您需要import { clearTimeout } from "timers";import { clearInterval } from 'timers';导入。

相关内容

最新更新