You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: ion-tab ionTabsWillChange event is fired after the tab component ngOnInit, ionViewWillEnter and ionViewDidEnter are fired #27212
navigate between tabs
Note that the ion-tab ionTabsWillChange event is fired after the tab component ngOnInit, ionViewWillEnter and ionViewDidEnter are fired - see below
changed the title [-]bug: [/-][+]bug: ion-tab ionTabsWillChange event is fired after the tab component ngOnInit, ionViewWillEnter and ionViewDidEnter are fired[/+]on Apr 17, 2023
Can you explain why ionTabsWillChange should be emitted before the other lifecycle events? In the current implementation, the event fires after the active tab is set (either manually through the API or from a user interaction). It isn't directly coupled to the child component's lifecycle.
Can you explain why ionTabsWillChange should be emitted before the other lifecycle events? In the current implementation, the event fires after the active tab is set (either manually through the API or from a user interaction). It isn't directly coupled to the child component's lifecycle.
The problem is that, in each tab component ngOnInit method, I need to get the active/selected tab and this is not available yet (as this is set in ionTabsWillChange which fired after the tab child component life cycle events invoked). My assumption, based on the event name ionTabsWillChange (note that it will change), this should happen before the tab components are loaded/initialized.
@ryaa appreciate the follow-up. I agree the event ordering here is not correct. The ion-tabs implementation is listening for the result from stackEvents, but this is emitted after the child component is mounted in the DOM and ngOnInit resolves.
ion-router-outlet should emit another event prior to setting the active view, allowing ion-tabs to emit ionTabsWillChange with the selected tab before it is activated. I do not believe our original resolution in #24910 was correct after reviewing this again.
Can you share your ideal implementation for accessing the selected tab from within the ngOnInit? Currently the child components would not have access to the ion-tabs event emission, even if we changed the ordering of when they fired. This data would need to be stored in a provider and shared between the component rendering ion-tabs and the inner child component.
Can you share your ideal implementation for accessing the selected tab from within the ngOnInit? Currently the child components would not have access to the ion-tabs event emission, even if we changed the ordering of when they fired. This data would need to be stored in a provider and shared between the component rendering ion-tabs and the inner child component.
Note that each tab component has a workaround in ngOnInit to set the correct value for the activeTab in Share provider. Ideally, this should be set once in onTabsWillChange in the main tabs page, so that all the individual tab child components etc. can read the correct activeTab value from Share provider.
I hope that it makes sense. Please let me know if you have any questions or comments. Thank you
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Activity
[-]bug: [/-][+]bug: ion-tab ionTabsWillChange event is fired after the tab component ngOnInit, ionViewWillEnter and ionViewDidEnter are fired[/+]sean-perkins commentedon Jul 5, 2023
Hello @ryaa thanks for reporting this issue!
Can you explain why
ionTabsWillChangeshould be emitted before the other lifecycle events? In the current implementation, the event fires after the active tab is set (either manually through the API or from a user interaction). It isn't directly coupled to the child component's lifecycle.This was a recent change here: #24910
This was done in response to this issue: #18900
ryaa commentedon Jul 10, 2023
The problem is that, in each tab component ngOnInit method, I need to get the active/selected tab and this is not available yet (as this is set in ionTabsWillChange which fired after the tab child component life cycle events invoked). My assumption, based on the event name ionTabsWillChange (note that it will change), this should happen before the tab components are loaded/initialized.
sean-perkins commentedon Jul 10, 2023
@ryaa appreciate the follow-up. I agree the event ordering here is not correct. The
ion-tabsimplementation is listening for the result fromstackEvents, but this is emitted after the child component is mounted in the DOM andngOnInitresolves.ion-router-outletshould emit another event prior to setting the active view, allowingion-tabsto emitionTabsWillChangewith the selected tab before it is activated. I do not believe our original resolution in #24910 was correct after reviewing this again.Can you share your ideal implementation for accessing the selected tab from within the
ngOnInit? Currently the child components would not have access to theion-tabsevent emission, even if we changed the ordering of when they fired. This data would need to be stored in a provider and shared between the component renderingion-tabsand the inner child component.ryaa commentedon Jul 12, 2023
Here is the sample showing a simplified implementation that I have in my application now - see https://stackblitz.com/edit/angular-jddxdk-qrddgc?file=src%2Fapp%2Fhome%2Fhome-page.component.ts
Note that each tab component has a workaround in
ngOnInitto set the correct value for the activeTab inShareprovider. Ideally, this should be set once inonTabsWillChangein the main tabs page, so that all the individual tab child components etc. can read the correct activeTab value fromShareprovider.I hope that it makes sense. Please let me know if you have any questions or comments. Thank you
sean-perkins commentedon Aug 14, 2023
Hello @ryaa, would you be available to test this dev-build and let me know if it resolves your issue?
Forked reproduction with the dev-build: https://stackblitz.com/edit/angular-jddxdk-rnznpn?file=package.json
Thanks!
ryaa commentedon Aug 15, 2023
sure. I will try to test in this week
fix(angular): ionTabsWillChange is fired before tab activation (#27991)
ionitron-bot commentedon Sep 17, 2023
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.