【发布时间】:2019-07-09 00:37:38
【问题描述】:
在 ionic 4 框架中,我使用 router.navigate 导航到页面。在导航页面中,构造函数和 ngOnInit 不会从第二次开始调用。仅第一次调用。
【问题讨论】:
-
请分享您的代码以供审核
在 ionic 4 框架中,我使用 router.navigate 导航到页面。在导航页面中,构造函数和 ngOnInit 不会从第二次开始调用。仅第一次调用。
【问题讨论】:
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.
【讨论】: