Show initial view when switching tabs


#1

Hey there!

This may be a angular routing question, but being new to ionic/angular I can’t seem to find the right search phrases to find a answer. Hopefully some of you pros can help me :wink:

As in this example my pages may include detail views (in the example the Home-page has a Scientific Facts -details). When opening detail views and moving from one tab to another the detail view is “still” open when returning to the Home-page.

How can I make pages to always show the “initial” state. Not the detail view which was last open when leaving the page? ie. clicking on the Home-tab should always show the Home-page (with the single button) not the detail view with all the “Facts”. (This preferably without clearing cache or state of detail view)

Thanks,
-Miika

PS. Will accept suitable search phrases as a answer


#2

use the on-select-attribute of a tab.
http://ionicframework.com/docs/api/directive/ionTab/

there you can define an own function, if you click on that tab or the tab is the active one
in that function you can route to you base view, if you are not there


#3

Thanks for the quick response, but without an example I didn’t see how it would work. That is what my “own function” would do/call.

Ended up with something like this (Try clicking the button on the About-page and move between tabs)

  • Added a parameter “main” to the About-page
  • Tied $state to $rootScope
  • About-tab now has a ng-click="$state.go(‘tabs.about’, {‘main’:true})"

I suppose it would be good to add something like $urlRouterProvider.when(’/tabs/about’, ‘/tabs/about/{main}’) as a fallback option?

If you gurus see something “wrong” with this solution please let me know.