Ionic2 Tabs life cycle


#1

I would like to share my understanding of Tabs life cycle :
Let’s say I have a TabsPage with 2 Tabs : Tab1Page, Tab2Page
Here is what happens when the TabsPage is requested :

PUSH TabsPage

CREATE TabsPage
CREATE Tab1PageModel (default Tab to display)
ENTER Tab1PageModel
ENTER TabsPage

–> Click tor Tab2
LEAVE Tab1Page
CREATE Tab2Page
ENTER Tab2Page

–> Click for Tab1
LEAVE Tab2Page
ENTER Tab1Page

–> Click Back to exit TabsPage
LEAVE Tab1Page
LEAVE TabsPage
DESTROY Tab1Page
DESTROY Tab2Page
DESTROY TabsPage

Note 1 : when you switch between 2 Tabs : neither destroy, nor unload happens
Note 2 : a Tab is not created until the user requests this specific tab
Important Note 3 : when a page or tab subscribes to an observable, this subscription is NOT destroyed when the page or tab is destroyed. Then make sure to unsubscribe in onDestroy() or the subscriptions will pile up each time the page or tab is created again.

Hope it can help newbies,
If I am wrong, please tell me :slight_smile: