What would be the best way to load a new page into Tab 2 once you have selected it? I can select Tab2 and the app changes to Tab2 but the āLoadDifferentTab2Pageā is pushed into the previous tab and not into Tab2?
goToTab2() {
//Here, we need to jump up to the parent nav
//basically the tabs page
//and call select form the Tabs api
this.nav.parent.select(1)
this.nav.push(LoadDifferentTab2Page, params, { animate: true });
In my case Iām in a page0 in tab0 and want to change to tab2 and push page2 so when the user clicks the Back they go to the root of tab2. I had to use setTimeout because the tab change seems to happen async. But this is very fragileā¦
There is a tab selected event that is fired and contains the selected tab. I guess I could push the desired page into the Tab so when it changes it could do the page push and then delete the desired page data. At least then it wonāt rely on the speed of the tab change.
What was the solution you tried? I tried to publish and event but once Iāve navigated away to the other page the event doesnāt seem to register. How did you get it working?
Did you figure out a better solution in the end up? I tried this solution here and it appeared to work, but I didnāt really understand how it worked. Whatās actually going on with the setTimeout() line of code?
AFAIK setTimeout() lets the main JS thread run so the select() will be performed (that will cause navCtrl.parentās selected tab to be updated). Then calling parent.getSelected() should return the newly selected tab. So then the push() happens on that tab instead of the previously selected tab which is what would have happened if you didnāt use setTimeout().
If select() was blocking or had a Promise interface you wouldnāt have to use this hack.