检查用户是否已滚动到Angular 2的底部
问题描述:
在没有jQuery的情况下,检查用户是否已滚动到Angular2页面底部的最佳实践是什么?我可以访问我的应用程序组件中的窗口吗?如果不是,我应该检查是否滚动到页脚组件的底部,我该怎么做?页脚组件上的指令?有人做到了吗?
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?
答
//您可以使用它.
@HostListener("window:scroll", [])
onScroll(): void {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
// you're at the bottom of the page
}
}