I want to execute some code every time the page changes.
I could add add an ngOnDestroy
method to every page. It appears that I could use Ionic 2 page lifec
You can use plain old Javascript to be placed in app.component.ts. Assuming that you use Ionic2-RC0:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { YourPage } from '../pages/yourpage/yourpage';
@Component({
template: ` `
})
export class MyApp {
rootPage = YourPage;
constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
window.addEventListener('load', () =>{
console.log('page changed');
});
});
}
Every time you change page using the NavController, you'll have page changed
printed out in the console.