yantrab
yantrab

Reputation: 2662

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

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>

Upvotes: 42

Views: 14318

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222582

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.

Upvotes: 192

ranbuch
ranbuch

Reputation: 1642

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.

Upvotes: 6

Related Questions