0

I want to execute a function when the scrollbar reaches the bottom of the page.

How do I know if the scroll has reached the end of the page?

@HostListener("window:scroll", [])
onScroll(): void {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        console.log('end')
    }
}

but it not work .

How can i do this work ????

mr-dortaj
  • 782
  • 4
  • 11
  • 28

1 Answers1

0

Using that example is pretty easy. You can use the code inside the component's .ts file to use it. Check out this demo on CodeSandBox. I have implemented the fiddle in angular.

Here you can see the full-screen preview of the demo.

halfer
  • 19,824
  • 17
  • 99
  • 186
Saqib
  • 704
  • 3
  • 18