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

查看:492
本文介绍了OnScroll事件Ionic 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();
    });
  }
}

但是我收到此错误无法读取未定义的属性'ionScroll'我把它放在错误的位置?

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执行:

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

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

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