File

projects/maplander/shared/src/lib/directives/infinite-scroll/infinite-scroll.directive.ts

Implements

AfterViewInit OnDestroy

Metadata

Selector [libScrollInfinite]

Index

Properties
Methods
Outputs

Constructor

constructor(el: ElementRef)
Parameters :
Name Type Optional
el ElementRef No

Outputs

infiniteScroll
Type : EventEmitter<void>

Methods

ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void

Properties

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);
  }

}

result-matching ""

    No results matching ""