OnScroll 事件离子 2 [英] OnScroll event Ionic 2

查看:28
本文介绍了OnScroll 事件离子 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在 Ionic 2 上滚动时拿起让我很困惑.我基本上想说,当用户向下滚动页面时,做一些事情.

Picking up when a user scroll on Ionic 2 is confusing me. I basically want to say, when a user scrolls down the page, do something.

任何例子都会很棒.

更新:

我的构造函数中有这个,所以当页面滚动时我想关闭键盘,因为它保持打开状态并且没有其他方法可以关闭.

I have this in my constructor, so when the page scrolls I want to close the keyboard, due to it being left open and no other way to close.

import { Component, ViewChild } from '@angular/core';
import { NavController, NavParams, Content } from 'ionic-angular';
import { Keyboard } from '@ionic-native/keyboard';

export class SearchPage {

  @ViewChild(Content)
  content:Content;

  constructor(public keyboard: Keyboard, public formBuilder: FormBuilder, public navCtrl: NavController, public navParams: NavParams, public apiAuthentication: ApiAuthentication, private http: Http) {

    this.content.ionScroll.subscribe((data)=>{
      this.keyboard.close();
    });
  }
}

但是我收到这个错误Cannot read property 'ionScroll' of undefined 我是不是把它放在错误的地方了?

However I get this error Cannot read property 'ionScroll' of undefined am i putting it in the wrong place?

推荐答案

您可以订阅内容事件.

内容有 3 个输出事件:

  • ionScroll 在每个滚动事件上发出.
  • ionScrollEnd 在滚动结束时发出.
  • ionScrollStart 在第一次开始滚动时发出.
  • ionScroll Emitted on every scroll event.
  • ionScrollEnd Emitted when scrolling ends.
  • ionScrollStart Emitted when the scrolling first starts.

收听事件:

@ViewChild(Content)
content: Content;
// ...
ngAfterViewInit() {
  this.content.ionScrollEnd.subscribe((data)=>{
    //... do things
  });
}

或者从 DOM 执行:

Or do it from the DOM:

<ion-content (ionScroll)="onScroll($event)">

对于 Ionic 4

<ion-content [scrollEvents]="true" (ionScroll)="onScroll($event)">

这篇关于OnScroll 事件离子 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆