-2

I have been going through articles that covers the same question however most of them are done using javascript. I want to accomplish this in Angular 4 and ironic 3.

Your assistance will be highly appreciated.

Tinyiko Chauke
  • 365
  • 2
  • 14
  • Possible duplicate of [Scroll to element on click in Angular 4](https://stackoverflow.com/questions/43945548/scroll-to-element-on-click-in-angular-4) – Jaykant Mar 06 '19 at 12:31

1 Answers1

1

For Ionic 2 and higher use the scrollToTop() method on the content class.

page.html

<ion-content>
  Add your content here!
</ion-content>

page.ts

import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';

@Component({...})
export class MyPage{
  @ViewChild(Content) content: Content;

  scrollToTop() {
    this.content.scrollToTop(400);
  }
}

Or you can call scrollTop() whenever you want. Note: 400 is duration in milliseconds, it is optional and you can use this as well

this.content.scrollToTop();

in this case scrollToTop() will set the default value of 300.

Janmejay Kumar
  • 309
  • 2
  • 7