1

I'm getting data from rest api in batches of 25.I'm using virtual scroll to display data.Now when these 25 items are scrolled,i need to query for next 25 items.How to detect when user reaches end of list ??

1 Answers1

0

Get reference of Virtual Scroll using the @ViewChild

 @ViewChild(CdkVirtualScrollViewport)
  viewport: CdkVirtualScrollViewport;

To check scroll reach to end using below code.

const end = this.viewport.getRenderedRange().end;

and using following condition you can determine the reached at end to load next items

const total = this.viewport.getDataLength();
if (end === total) {
    //Load next items
}

Here is example infinite-virtual-scroll-angular

TheParam
  • 8,324
  • 1
  • 30
  • 40