Capturing ion-tab click on active tab event

#1

Hi,
I want to execute a method when a user clicks on the active ion-tab.

I tried (ionChange)="myFunction()" in the ion-tabs parent element, but that only fires when the tab changes. I want to capture the event even when the tab doesn’t change (final goal is to make the current tab reload itself / scroll up).

Any ideas on how to achieve this with Ionic 2?

1 Like
#2

I guess this is not possible with the current Beta … :confused:

#3

Might help to check the docs for this.

<ion-tabs>
  <ion-tab [root]="tab1Root" (ionSelect)="myMethod()"></ion-tab>
  <ion-tab [root]="tab2Root"></ion-tab>
  <ion-tab [root]="tab3Root"></ion-tab>
</ion-tabs>
9 Likes
Is it possible to trigger menuToggle with an <ion-tab>?
#4

Hi @mhartington, thank you for your reply. I have tried exactly what you posted before as well.

The issue with that solution is that (ionSelect) only fires when the selection changes.

Because the selection does not change when you select an already active tab, it does not fire. Therefore I can’t use it for my purposes. I need something that fires even when it selects the same tab that you are on.

1 Like
#5

did you found a way to resolve it? I’m trying to implement the same behaviour on my app.

#6

No, I did not find any way to solve it. I still have the issue.

I also did not get any further response from @mhartington or the Ionic Team about this issue, a bit sad really :confused: looks like this is currently not possible.

#7

Hi,

I have the same issue any updates ?

#8

Try something like this:

<ion-tabs>
  <ion-tab [root]="tab1Root" (click)="myMethod()"></ion-tab>
  <ion-tab [root]="tab2Root"></ion-tab>
  <ion-tab [root]="tab3Root"></ion-tab>
</ion-tabs>
#9

Putting (click)=“myMethod()” responds to the contents of the tab being clicked on, rather than the tab selector itself.

#10

Any news on this? Im trying to have a different page show up when the active tab is clicked. Any help would be greatly appreciated!

#11

I have the same question/need, and I asked it in the forum as well, with no replies.

#12

This has been fixed in RC 2! use (ionSelect) by itself.

#13

This doesn’t seem to work for me (in RC2). When the tab A is being viewed and tab B is selected then ionSelect fires. When tab B is viewed and tab B is selected then ionSelect does not fire.
The goal is to be able to detect tab B was selected when tab B contents were being viewed, this is to allow some refresh/view reset/scroll to top to occur

2 Likes
#14

You have it exactly.

#15

Same wish there was a way to do this.

#16

I used it to open a model so that they don’t have to press again for the behavior. Plus, how frequently do users click the active tab?

#17

I need it too, I want to use it to show unread messages on top in active tab.

#18

In adittion to this, I need a MouseEvent class.

e.g.

(click)=“myMethod($event)”

ionSelect don’t provide a mouseEvent. So, I can’t use a popover in a correct position.

1 Like
#19

I’d like to solve for the same feature as @danielabbatt - it is, for many heavy mobile users, a known action when you click on an already active tab you will scroll to the top of that tab page, so you don’t have to manually scroll all the way back up if you’ve been going through a number of search results, or something similar. Any response/solution for this yet?

#20

To resolve this issue, you need to modify from the source code for now
inside the ionic project at node_modules\ionic-angular\components\tabs\tabs.js (or tabs.ts)

In different rc build, the source code of tabs.js(or tabs.ts) might be different.

Basically, the guideline is in the select tab function

Tabs.prototype.select = function (tabOrIndex, opts)

if (selectedTab.root) //this is the active tab
you will still need to file the event and the code is
this.ionChange.emit(selectedTab);

Hope it is helpful for the people who is looking for the solution.
This is very inconvenience that can’t select the active tab for some scenarios.