What Are The Ionic Lifecycle Events?

Technology CommunityCategory: IonicWhat Are The Ionic Lifecycle Events?
VietMX Staff asked 3 years ago

Ionic pages are usually converted into an Angular component as we are aware Ionic frame is built on top of Angular. Just like Angular frameworks has its lifecycle hooks which we follow during the development of Web Application. Also, lifecycle events for ionic framework help in capturing and performing some specific task.

  • ionViewWillEnter: This event is fired when component routing is about to animate into view. i.e ionViewWillEnter() lifecycle function signifies that all the process to make your page in full view and transitioned in is about to begin and your page has been queued to be pushed into view.
  • ionViewDidEnter: When this event is fired, your page is completely loaded and completely available to view alongside the animation. In other words, this event is fired when the component routing have finished.
  • ionViewWillLeave: This event is fired when your page gets the information of getting out from the active state of the page but, it is still in the active state only. In other words, we can say that this event is fired when the component routing from is about to animate. This kind of event is useful to start preparing for the things for the next view before navigating.
  • ionViewDidLeave: This event is fired when the component routing to has finished animating. Now, this event indicates that your ionic page is no longer in focus and leave the active state of the page. Also, this event is fired after the ionViewDidEnter event. This kind of events is fired to free up the memory resources.

There are some more lifecycle events which would prevent unauthorized access of users.

  • ionViewcanEnter: which is fired before entering into a view, allows you to control whether the view can be controlled or not by the user.
  • ionViewCanLeave: which is activated before leaving a view which allows you to control whether the view can be left or not by the user.

In Ionic 4 the above mention two events can be replaced with Routing Guards.