import { Directive , ElementRef , EventEmitter , OnDestroy , Output } from '@angular/core' ; @ Directive ( { selector : '[ngxChatIntersectionObserver]' , } ) export class IntersectionObserverDirective implements OnDestroy { @ Output ( ) ngxChatIntersectionObserver = new EventEmitter ( ) ; private intersectionObserver : IntersectionObserver ; constructor ( private el ) { this . intersectionObserver = new IntersectionObserver ( ( entries ) => { this . ngxChatIntersectionObserver . emit ( entries [ 0 ] ) ; } , { rootMargin : '150px 0px 150px 0px' , } ) ; this . intersectionObserver . observe ( el . nativeElement ) ; } ngOnDestroy ( ) { this . intersectionObserver . disconnect ( ) ; } }