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.
@ViewChild('mainTabs') mainTabs: Tabs;
constructor(public nav:NavController, public events: Events ) {}
// This will be executed before ionChange event
public tapped() {
this.events.publish('home:scrollToTop', Date.now() );
}
home.ts
[...]
@ViewChild(Content) content: Content;
constructor(public app: App, public nav: NavController, public events: Events, private logic:StpLogicService) {
// NOTE: This will be executed only when home is already the active/current tab
events.subscribe('home:scrollToTop', (time) => {
console.log('home:scrollToTop', 'at', time);
this.content.scrollToTop();
});
}
The effect is: Homepage si scrolled to top only when already displayed.
Does anyone have another solution for this issue? When I try to use BLaCkSMiTH77 solution, my content scrolls also when I scroll down to a button and push from there a new View on the Viewstack which should not happen! The other solutions does not work for me but I dont know how to use ionSelected() as markharding replied.
I noticed that when I click an already selected tab, it gets destroyed and recreated again. What’s even worse, the “rootParams” specified in the Tabs are not passed to the page when recreating. Do you think this is a bug?
When I add the ionSelected() method, the tab page won’t be recreated so that solved my problem. Is this method documented somewhere? I couldn’t find it anywhere else than here.
It seems it is best to add an empty ionSelected to every tab page to prevent recreating the page and to avoid unexpected bugs. It’s a bit strange it isn’t documented properly anywhere.