ionic 2 page change event

前端 未结 6 2506
深忆病人
深忆病人 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:23

    1st thing Router is present in @angular/router module.

    And for listening route change event you can place subscription on router changes object.

    Code

    class MyRouteEventClass {
      constructor(private router: Router) {
         router.changes.subscribe((val) => {
           /* Awesome code here */
         }
        )
      }
    }
    

提交回复
热议问题