How to enable going back to main tab?


#1

I got three views, cars index, car picture and misc view. From index there’s links to car picture. If I move like this: 1. Index, 2. Open picture, 3. Go to misc view (under tabs), 4. Click the ‘cars index’ tab, the previous car picture view opens. Desired option would be to go into the index again.

.state('tab.cars-index',   {
   url: '/cars',             
   views: { 'cars-tab':    { 
       templateUrl: 'templates/car-index.html',  
       controller: 'carIndexCtrl' 
 }}})
.state('tab.car-picture',  { 
   url: "/picture/:id",      
   views: { 'cars-tab':    { 
       templateUrl: "templates/car-picture.html", 
       controller: 'PictureCtrl' }}}) 
.state('tab.other',  { 
   url: "/other",      
   views: { 'other-tab':    { 
       templateUrl: "templates/car-picture.html", 
       controller: 'PictureCtrl' }}}) 

So the tab.car-picture should have views: {‘someother-tab’}, but if I put something else there, it doesn’t work anymore. What am I doing wrong?


#2

I’m also curious if there’s a simple way to do this. Thanks


#3

Here’s what I came up with:

  <ion-tabs class="tabs-positive tabs-icon-only" ng-controller="TabsCtrl">
         <ion-tab href="#/tab/home" title="Browse" icon-on="ion-ios7-browsers" icon-off="ion-ios7-browsers-outline">
             <ion-nav-view name="home-tab"></ion-nav-view>
         </ion-tab>
        <ion-tab ng-click="doCreateTabClick()" title="Create" 
            icon-on="ion-ios7-plus" icon-off="ion-ios7-plus-outline">
            <ion-nav-view name="create-tab"></ion-nav-view>
        </ion-tab>
  </ion-tabs>

And add this TabsCtrl to your app somewhere

.controller('TabsCtrl', ['$scope', '$location', '$state', function($scope, $location, $state) {
    $scope.doCreateTabClick = function() {
        $state.go("tab.create-choose-type");
    }
}]);

So this way when the user taps this specific tab it will force the state to whatever you want, rather than following the href as usual. First tab behaves normally, with tab history. Second one always goes to the initial view.