I am showing the data related to the search term. This data shows all the results at once.
What I want to do is show 6 data once and load the remaining on a scroll.
<li *ngFor="let category of categories">
{{ category.name }}
</li>
How can I show data on scroll?
Loading hundreds of elements can be slow in any browser; virtual scrolling enables a performant way to simulate all items being rendered by making the height of the container element the same as the height of total number of elements to be rendered, and then only rendering the items in view.
You could listen to the window:scroll
events and load data when the scroll reaches the bottom of the page :
@HostListener("window:scroll", [])
onScroll(): void {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
// Load Your Data Here
}
}
Here is a running stackblitz.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With