To auto load data using scroll, we can get the element or div scrollHeight and match with window scroll Y axis height and execute. Here is the code below. Hope it helps
results.component.ts
page: number = 1; @HostListener('window:scroll', ['$event']) scrollHandler(event: any) { var insightsResults = document.getElementsByClassName( 'insights-results' )[0]; var childInsights = insightsResults?.scrollHeight; var windowScroll = window.scrollY; if (Math.floor(windowScroll) >= Math.floor(childInsights)) { this.loadMore(); } } loadMore(): void { this.page++; }
results.component.html
<ul *ngIf="insights && insights.length" class="insights-results__card-list" (scroll)="scrollHandler($event)"> <li class="insights-results__card" *ngFor="let card of insights | slice: 0:pageSize * page"> <app-insights-card [locale]="locale" [data]="card" variant="vertical" ></app-insights-card> </li> </ul> <div *ngIf="insights && insights.length > pageSize * page" class="insights-results__button-wrapper"> <button class="insights-results__button" (click)="loadMore()" [disabled]="pageLoading"> <span *ngIf="!pageLoading">{{ data.seeMoreResultsCtaText }}</span> <span *ngIf="pageLoading">{{ data.loadingText }}</span> </button> </div>