【问题标题】:Impossibile to detect scroll of the page in Angular无法检测 Angular 中的页面滚动
【发布时间】:2020-12-30 00:59:53
【问题描述】:

我在检测 Angular 中的窗口滚动时遇到了一些问题:

    @HostListener("window:scroll", [])
  onWindowScroll() {
   
    console.log("ciao");
  }

我哪里错了?

【问题讨论】:

标签: javascript angular


【解决方案1】:

改用这个

 @HostListener('window:scroll', ['$event']) // for window scroll events
    onScroll(event) {
      ...
    }

或针对特定的 div

 <div (scroll)="onScroll($event)"></div>

【讨论】:

【解决方案2】:

试试这个实现

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2015-07-07
    • 1970-01-01
    相关资源
    最近更新 更多