Selecting tab from controller won't work


#1

Hey there,

I have an app with multiple pages that have tabs. Every tab has lists with links on them.

When I open a detailed view from one of those lists I want to return to the same tab where I clicked the link in.

So I’m storing the tab that was opened in local storage with this function in my controller:

 $scope.storeTab = function(tab_number){
    $ionicTabsDelegate.select(tab_number);
    StorageHandler.handle('localdata.open_tab',tab_number);
    console.log('just stored tab '+StorageHandler.handle('localdata.open_tab') );
  }

This is triggered in the partial view by using <ion-tab title="Room" ng-click="storeTab(1)"> etc.

This is working great. The only thing I’m having problems with is actually opening the correct tab upon going back.

When I use:

  var open_tab = StorageHandler.handle('localdata.open_tab');
  $ionicTabsDelegate.select(open_tab);

in my controller, the tabs won’t switch. I’ve tried adding a delegate handle to the tabs, and using a timeout on the select function. But nothing. Am I using this correctly? I’m using the nightly btw.

Anybody know what I’m doing wrong?


#2

Have you gotten anywhere with this?

I setup this sample : http://codepen.io/calendee/pen/Ffwxv?editors=101

Go to the “About” tab and click the “Go To Home By Id” button. The view just goes blank. Is this what you’re experiencing?

If so, I’ll buzz the devs to see if we’re doing something wrong.


#3

Nope, unfortunately not.

Check out this Codepen: http://codepen.io/squrler/pen/septI

Using a timeout or $timeout on the switching to the tab doesn’t work, and I can’t figure out why not. @Calendee you have any idea?


#4

I finally got this to work.

This one is using a delegate-handle : http://codepen.io/calendee/pen/Jxiaj

This one doesn’t use handler : http://codepen.io/calendee/pen/bIcaK


#5

Nice!

So it was basically just parsing the value from localstorage as an integer in combination with a $timeout of at least 100ms.

Awesome!