Determine Which Tab is Showing

The tab.shown and tab.hidden events get fired for any tab change in every controller (for instance, if you have one controller per tab, and catch the tab.shown event and issue an alert, you’ll see an alert from every controller every time any tab is shown) - is there an event or way to determine which tab is being shown or hidden so we can run code only when the “current” tab is switched to?

1 Like

I’m still hoping there’s a better/supported way to determine the current tab, but it looks like the rootScope gets a tabIndex, so you can always check $scope.tabIndex to see a numeric index of which tab has been clicked. It’s something.

Looks like this behavior changed back in January to address a bug. The fix changed the event from the tab’s $scope to $rootScope. Hopefully someone from the Ionic team can look at this and either revert or suggest a better way to track tab changes?

1 Like

Thanks for pointing this out. I created an issue and this time we’ll put more tests in place:

This is fixed in 0.9.25