Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
OnScroll event 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.

Any examples would be great.

UPDATE:

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();
    });
  }
}

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

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can subscribe to content events.

Content has 3 output events:

  • ionScroll Emitted on every scroll event.
  • ionScrollEnd Emitted when scrolling ends.
  • ionScrollStart Emitted when the scrolling first starts.

Listen to an event:

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

Or do it from the DOM:

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

For Ionic 4

<ion-content [scrollEvents]="true" (ionScroll)="onScroll($event)">
about 4 years ago · Santiago Trujillo Relatório

0

You can use ngOnInit method to register the scroll event :

ngOnInit() {
   if (this.content) {
      this.content.ionScroll.subscribe((data)=>
        this.keyboard.close();
      });
    }
  }
about 4 years ago · Santiago Trujillo Relatório

0

When inside a custom directive try with something like this:

import { Renderer2 } from '@angular/core';
...
constructor(private renderer: Renderer2) {}

ngOnInit() {
    this.renderer.listen(this.myElement, 'scroll', (event) => {
        // Do something with 'event'
        console.log(this.myElement.scrollTop);
    });
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda