Ionic 4 : ngOnInit vs ionViewWillEnter Ionic 4 : ngOnInit vs ionViewWillEnter angular angular

Ionic 4 : ngOnInit vs ionViewWillEnter


ionViewWillEnter — Fired when entering a page (also if it’s come back from stack)

ngOnInit will not be triggered, if you come back to a page after putting it into a stack

i think better once ionviewwillenter


The Ionic 4 migration guide puts it this way:

With V4, we're now able to utilize the typical events provided by Angular. But for certain cases, you might want to have access to the events fired when a component has finished animating during it's route change. In this case, the ionViewWillEnter, ionViewDidEnter, ionViewWillLeave, and ionViewDidLeave have been ported over from V3. Use these events to coordinate actions with Ionic's own animations system.

So the bottom line is to prefer Angular lifecycle hooks like ngOnInit if possible. The only real exception is dealing with Ionics animation system like checking if a component has finished it's entering animation.


In Ionic 4 Life cycle events are same as angular life cycle events.Ionic 3 Life cycle events not worked here.

For Initialization you must use

ngOnInit()

If you want after view initialized,

Please change

ionviewwillenter

to

ngAfterViewInit()

This will works Fine.