Skip to content

Commit cfe2ff5

Browse files
committed
Implement ngOnDestroy cleanup.
1 parent 3162df8 commit cfe2ff5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/app/public/ngx-scroll-top.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Component,
33
HostBinding,
44
HostListener,
5+
OnDestroy,
56
OnInit,
67
input,
78
signal,
@@ -14,7 +15,7 @@ import {
1415
imports: [],
1516
standalone: true,
1617
})
17-
export class NgxScrollTopComponent implements OnInit {
18+
export class NgxScrollTopComponent implements OnInit, OnDestroy {
1819
/**
1920
* Background color of the back to top button (hex string).
2021
*
@@ -161,6 +162,15 @@ export class NgxScrollTopComponent implements OnInit {
161162
this.updatePosition();
162163
}
163164

165+
public ngOnDestroy(): void {
166+
if (this.fadeTimeout) {
167+
clearTimeout(this.fadeTimeout);
168+
}
169+
if (this.animationFrameId) {
170+
cancelAnimationFrame(this.animationFrameId);
171+
}
172+
}
173+
164174
/** Scroll smoothly to the top of the window. */
165175
public scrollTop(): void {
166176
window.scroll({

0 commit comments

Comments
 (0)