ionic 2 page change event

前端 未结 6 2509
深忆病人
深忆病人 2021-02-18 20:38

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

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-18 21:16

    In Ionic2+ you can simply subscribe to the event you want to execute your code on as follows:

    this.navCtrl.ionViewWillUnload.subscribe(view => {
        console.log(view);
    });
    

    You can subscribe to all the Lifecycle Events

提交回复
热议问题