How do we trigger to scroll to top in ionic 2? ionic 1 had some delegates to do this, but not sure how i can do this in ionic 2. Some use case might be
If sidemenu has a long list of menus, and if one touches the menu than scroll to the top of the list in sidemenu.
Also would love to know how to scroll to specific element in ionic 2 as well.
is it possible to only scrollToTop when a tab is changed, i tried doing it in the components viewDidload but that occurs everytime a page is in view coming back to the page from a sub-page, for example users list, item clicked, go back to users list and the scrollToTop will occur.
<ion-content #pageTop>
<!-- Other content here -->
</ion-content>
In your .ts file
import { Content } from 'ionic-angular';
//
//...
//
export class ScrollPage{
@ViewChild('pageTop') pageTop: Content;
/**
* Method to scroll to top
*/
public pageScroller(){
//scroll to page top
this.pageTop.scrollToTop();
}
}
I suggest, just replace one line, if there is some error in @ViewChild(IonContent) content: IonContent;
to @ViewChild(IonContent, {static: true}) content: IonContent;
I tried using this method. But I want my page to scroll up when the slide changes not with a button click.
I tried implementing the method in a slidedidchange method and calling it in the (ionSlidesDidChange) parameter, but nothing happens everytime i change the slide. And i also have other code in the slide did change method which is working find so the method is being activate it as it suppose to. the scrolltoTop implementation is not working for me … Example below: