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
Ionic2
doesn't use Angular2's Router
. They have their own implementation NavController
.
I see that you can subscribe to Angular 2 Router events. How do I translate that for use in Ionic 2?
You can merge all the NavController Events
and subscribe to it.
allEvents = Observable.merge(
this.navController.viewDidLoad,
this.navController.viewWillEnter,
this.navController.viewDidEnter,
this.navController.viewWillLeave,
this.navController.viewDidLeave,
this.navController.viewWillUnload);
allEvents.subscribe((e) => {
console.log(e);
});