当我清除间隔时出现此错误:
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';
导入。