Run function when an ionic 2 page has fully loaded

You can use the lifecycle callback ngAfterViewInit() of the component that is loaded last (depends on your routing).


You can use the ionViewDidLoad method:

@Page({
  templateUrl: 'build/pages/somepage/somepage.html'
})
export class SomePage {
  constructor() {
    // ...
  }

  ionViewDidLoad() {
    // Put here the code you want to execute
  }
}

The lifecycle events as November 18, 2016 are:

  • ionViewDidLoad
  • ionViewWillEnter
  • ionViewDidEnter
  • ionViewWillLeave
  • ionViewDidLeave
  • ionViewWillUnload
  • ionViewCanEnter

Since Ionic 2 is in active development, things change all the time. If you would like to check the current lifecycle events, please refer to: https://ionicframework.com/docs/v2/api/navigation/NavController/#lifecycle-events