Check if user has scrolled to the bottom in Angular 2

C. Kearns picture C. Kearns · Jul 7, 2016 · Viewed 20.3k times · Source

What is the best practice to check if user has scrolled to the bottom of the page in Angular2 without jQuery? Do I have access to the window in my app component? If not should i check for scrolling to the bottom of the footer component, and how would I do that? A directive on the footer component? Has anyone accomplished this?

Answer

mayur picture mayur · Jul 7, 2016

// You can use this.

@HostListener("window:scroll", [])
onScroll(): void {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        // you're at the bottom of the page
    }
}