【问题标题】:Can't catch scroll event IONIC V3无法捕捉滚动事件 IONIC V3
【发布时间】:2019-12-29 23:45:24
【问题描述】:

我似乎无法从 Ionic 3 中的离子内容中捕捉到滚动事件。 我需要一个 div 元素中的每个滚动,以捕获滚动事件以执行一些相关的计算。

我尝试了几种方法,包括将 EventEmitter (ionScroll) 绑定到 HTML 文件中的方法,或者将 ion-content 声明为 viewchild 并尝试在 ngAfterViewInit() 方法中订阅它,但都没有工作。

我要绑定的方法很简单:

 scrolling(event) {
   console.log(event);
 }

HTML 文件:

<ion-content    style="height: 20000px;" (ionScroll)="scrolling($event)" >
</ion-content>

值得一提的是,这是项目中 home.html 页面中的一个组件。

我做错了什么?

【问题讨论】:

    标签: html ionic-framework scroll ionic3


    【解决方案1】:
    import {Component, ViewChild} from '@angular/core';
    import {Content} from 'ionic-angular';
    @Component({
         selector: 'page-home',
       templateUrl: 'home.html',
    })
    export class ProjectPage {
        @ViewChild(Content) content:Content;
    
        ngAfterViewInit() {
           this.content.addScrollListener((event) =>  {
               //on scroll fire
           });
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-10
      • 2011-06-07
      • 2017-07-27
      • 2012-12-19
      • 2021-07-14
      • 2021-11-15
      • 2017-01-22
      • 2014-06-04
      相关资源
      最近更新 更多