I want to log something when a user clicks on a tab. How can I do this?
Unfortunately (ionSelect) is not the answer as this is only triggered when the tab is selected, so when the execution of all the previous code is already done. I need an event as near as possible to the action the user triggers.
It doesnt seem to be firing.
Here is my code: tabs.html <ion-tab [root]="tab1Root" tabTitle="Title" tabIcon="pricetag" (ionChange)="eventTest()" #specialsTab></ion-tab> tabs.ts
console.log('click please');
}```
Anything I am missing?
ionSelected() only “triggers” when you are already on that tab I think. It can not be used to find out when someone clicks on a “new” tab to switch to it. Or did I miss anything?
Edit: I think this is the code for it - only occurence of ionSelected in all of Ionic:
I get suspicious when people ask questions about minutia of framework event timing. In my experience, that sort of thing is not very reliable. Can you not design things so that you can be a bit more flexible as far as precise sequencing goes?
I hate tabs because there’s always some weird issue like this. But maybe you could solve this completely differently. Have a provider subscribe to NavController.viewWillEnter() and take the desired step whenever a (different) root tabs page is the newly entered page.
In this case I just want to understand the timing of things - when does the user click, how long does it take for the tab to be switched successfully and data shown?
But to start doing things that need to happen after a tab is selected as soon as possible is always a good thing, isn’t it? There really is no reason why this shouldn’t be possible for tabs.
Won’t this be identical to implementing an ionViewWillEnter() on the page of the tab being navigated to?
That I already have right now and is the earliest “event” I could find.
I’ll put it this way: if you have to worry about this, then you’re doing too much (synchronous) heavy work in constructors and lifecycle events, or your templates are overcomplicated. If everything you do in there is asynchronous and straightforward, the framework overhead should be imperceptible.
If this is basically for testing/profiling purposes, then perhaps you could try adding event listeners directly to the anchor tags that actually take the click of the tabs first I think.
Hmm dirty and hackish… but of course might work!
(Hoping someone comes forward with a “this is supported by Ionic out of the box” solution before I try this though)