Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "timeout.close is not a function" when try to clear interval - angular(5)

Tags:

angular

I get this error when i do clear interval:

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 

The set interval function:

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

And the destroy function:

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

The component destroy with ngIf in parent component:

<test *ngIf="data.length" </test> 
like image 522
yantrab Avatar asked Jan 01 '18 03:01

yantrab


2 Answers

It's because of your IDE! Make sure your IDE didn't include automatic imports such as

import { clearInterval } from 'timers';  

If so, remove them. Rest should be fine.

like image 93
Sajeetharan Avatar answered Sep 21 '22 21:09

Sajeetharan


Had the same problem with clearTimeout.

using window.clearTimeout instead of clearTimeout works too in case you need the import { clearTimeout } from "timers"; or import { clearInterval } from 'timers'; imports.

like image 36
ranbuch Avatar answered Sep 22 '22 21:09

ranbuch