import { Directive, ElementRef, HostListener } from '@angular/core'; @Directive({ selector: '[appStopScroll]', }) export class StopScrollDirective { constructor(private el: ElementRef) {} @HostListener('wheel', ['$event']) onWheel(event: WheelEvent) { const element = this.el.nativeElement; // Check if scrolling is at the top or bottom of the element const atTop = element.scrollTop === 0; const atBottom = element.scrollHeight - element.scrollTop === element.clientHeight; // Prevent scrolling the page if scrolling is within the dropdown if ((atTop && event.deltaY < 0) || (atBottom && event.deltaY > 0)) { event.stopPropagation(); event.preventDefault(); } } }