44 Input ,
55 ViewChild ,
66 type AfterViewInit ,
7+ type OnDestroy ,
78 ViewEncapsulation ,
89} from '@angular/core' ;
910import type { ElementRef } from '@angular/core' ;
@@ -21,7 +22,7 @@ import { EventDisplayService } from '../../../services/event-display.service';
2122 styleUrls : [ './overlay.component.scss' ] ,
2223 encapsulation : ViewEncapsulation . None ,
2324} )
24- export class OverlayComponent implements AfterViewInit {
25+ export class OverlayComponent implements AfterViewInit , OnDestroy {
2526 /** Title of the overlay. */
2627 @Input ( ) overlayTitle : string ;
2728 /** If the overlay is open or not. */
@@ -39,6 +40,9 @@ export class OverlayComponent implements AfterViewInit {
3940 /** Aspect ratio of the overlay view. */
4041 aspectRatio : number = window . innerWidth / window . innerHeight ;
4142
43+ /** Bound resize handler for cleanup. */
44+ private resizeHandler = ( ) => this . resetHandlePosition ( ) ;
45+
4246 // ********************************************************************************
4347 // * Below code is specific to the overlay resize feature. (LOOK INTO CSS RESIZE) *
4448 // ********************************************************************************
@@ -70,12 +74,17 @@ export class OverlayComponent implements AfterViewInit {
7074 this . resetHandlePosition ( ) ;
7175 } ) ;
7276
73- window . addEventListener ( 'resize' , ( ) => {
74- this . resetHandlePosition ( ) ;
75- } ) ;
77+ window . addEventListener ( 'resize' , this . resizeHandler ) ;
7678 }
7779 }
7880
81+ /**
82+ * Clean up event listeners when the component is destroyed.
83+ */
84+ ngOnDestroy ( ) {
85+ window . removeEventListener ( 'resize' , this . resizeHandler ) ;
86+ }
87+
7988 /**
8089 * Resize the overlay card when the resize handle is dragged.
8190 */
0 commit comments