projects/maplander/shared/src/lib/directives/infinite-scroll/infinite-scroll.directive.ts
Selector | [libScrollInfinite] |
Properties |
|
Methods |
Outputs |
constructor(el: ElementRef)
|
||||||
Parameters :
|
infiniteScroll | |
Type : EventEmitter<void>
|
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
Private _scrollListener |
Type : Function
|
import {AfterViewInit, Directive, ElementRef, EventEmitter, OnDestroy, Output} from '@angular/core';
@Directive({
selector: '[libScrollInfinite]'
})
export class InfiniteScrollDirective implements AfterViewInit, OnDestroy {
@Output() infiniteScroll: EventEmitter<void>;
private _scrollListener: Function;
constructor(
private el: ElementRef
) {
this.infiniteScroll = new EventEmitter();
}
ngAfterViewInit(): void {
this._scrollListener = (ev: any) => {
const element = ev.srcElement;
if (Math.round(element.scrollTop + element.clientHeight) >= element.scrollHeight) {
this.infiniteScroll.emit();
}
};
this.el.nativeElement.addEventListener('scroll', this._scrollListener);
}
ngOnDestroy(): void {
this.el.nativeElement.removeEventListener('scroll', this._scrollListener);
}
}