我清除间隔时出现此错误:
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
Run Code Online (Sandbox Code Playgroud)
设定间隔功能:
this.inrvl = setInterval(() => loop(+new Date()), 5);
Run Code Online (Sandbox Code Playgroud)
和破坏功能:
ngOnDestroy(): void {
if (this.inrvl) clearInterval(this.inrvl)
}
Run Code Online (Sandbox Code Playgroud)
组件在父组件中使用ngIf销毁:
<test *ngIf="data.length" </test>
Run Code Online (Sandbox Code Playgroud)
Saj*_*ran 66
这是因为你的IDE!确保添加了自动导入,例如
import { clearInterval } from 'timers';
Run Code Online (Sandbox Code Playgroud)
如果是这样,请删除它们.休息应该没问题.
有同样的问题clearTimeout。
如果您需要或导入,使用window.clearTimeout代替也clearTimeout可以工作。import { clearTimeout } from "timers";import { clearInterval } from 'timers';
| 归档时间: |
|
| 查看次数: |
4924 次 |
| 最近记录: |