使用router.navigate从上一页导航时未调用ngOnInit和Constructor

时间:2019-07-08 14:41:03

标签: angular ionic4

在ionic 4框架中,我已经使用router.navigate导航到该页面。在导航的页面中,构造函数和ngOnInit不会从第二次调用。第一次才打电话。

1 个答案:

答案 0 :(得分:0)

ngOnInit()在组件初始化期间触发一次。我认为您的页面是一个子组件。子组件仅在其父组件被破坏时才会被破坏。这就是构造函数和ngOninit不第二次调用的原因。除了Angular生命周期事件外, Ionic Angular提供了一些其他事件,您可以使用

ionViewWillEnter() - Fired when the component routing to is about to animate into view.  
ionViewDidEnter() - Fired when the component routing to has finished animating.  
ionViewWillLeave() - Fired when the component routing from is about to animate.  
ionViewDidLeave() - Fired when the component routing to has finished animating.

了解更多详细信息:-https://ionicframework.com/docs/angular/lifecycle

相关问题