import { Injectable } from '@angular/core' ; import { CollectionParameters } from '../../services/models/api-parameter' ; @ Injectable ( { providedIn : 'root' } ) export class InfiniteScrollService { private apiCollection = new Map < string , CollectionParameters > ( ) ; /**
     * Detecting scroll direction
     */ private scrollTop : number = 0 ; private clientHeight : number = 0 ; private scrollHeight : number = 0 ; param event param unique public bottomReached ( event , unique ) { this . scrollTop = ( event . target as Element ) . scrollTop ; this . clientHeight = ( event . target as Element ) . clientHeight ; this . scrollHeight = ( event . target as Element ) . scrollHeight ; return this . scrollUp ( unique ) && Math . round ( ( this . scrollTop + this . clientHeight ) - this . scrollHeight ) === 0 ; } param page param limit param sort param order param unique public setCollectionParameters ( page , limit , sort ? , order ? , unique ? ) { const apiParams = { page , limit , sort , order , optional : { lastScroll : this . scrollTop } } ; this . apiCollection . set ( unique , apiParams ) ; } param unique return public getCollectionParameters ( unique ) { return this . apiCollection . get ( unique ) ; } param unique return private scrollUp ( unique ) { return this . scrollTop > ( this . apiCollection . get ( unique ) . optional as any ) . lastScroll ; } }