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 ??
Asked
Active
Viewed 2,208 times
2 Answers
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
- 10,113
- 4
- 40
- 51
-
I tried it .It returns zero in both end and total.Do you have any idea about it ?? – Simran Chawla Jan 23 '19 at 06:59
0
Get the scroll component as a child in the parent component
@ViewChild(CdkVirtualScrollViewport)
viewport: CdkVirtualScrollViewport;
Add a method that is triggered when scrolling happens
scrollEvent(): void {
if (this.viewPort.measureScrollOffset('bottom') < 10) {
// scrolled to the bottom, change
}
}
Trigger this method on the scroll
<cdk-virtual-scroll-viewport (scrolledIndexChange)="scrollEvent()"></cdk-virtual-scroll-viewport>

Peter Stručka
- 36
- 2