Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular “错误”;timeout.close不是一个函数;尝试清除间隔时-角度(5)_Angular - Fatal编程技术网

Angular “错误”;timeout.close不是一个函数;尝试清除间隔时-角度(5)

Angular “错误”;timeout.close不是一个函数;尝试清除间隔时-角度(5),angular,Angular,当我清除间隔时,会出现此错误: 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 设置间隔功能

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

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)
}
以及销毁功能:

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
也可以在需要从“timers”导入{clearTimeout}的情况下工作
从“计时器”导入{clearInterval}导入。

如果您是从“计时器”导入此<代码>导入{clearTimeout}请删除然后检查它是否对我有效。Holly F**由于IDE秘密导入它,我损失了半个小时。有人会认为会有一个弹出窗口,说你想自动导入bla-bla。