How to make the latest added tab active


#1

@mhartington
hi! I am adding tabs dynamically like this demo http://codepen.io/mhartington/pen/Cfqtr
The issue is I want that the newly added tab must be active. Right now only first tab is active and I have to tap the new tab to active.
Please help me how to nonactive the previous active tab and make active the newly added tab.

Thanks!


#2

Hey there,

http://ionicframework.com/docs/api/service/$ionicTabsDelegate/
You can find a method called “select” where you can select a tab.
If you add a tab -> call that select method and activate your created tab :wink:

Greetz, bengtler


#3

you could use $ionicTabsDelegate.select
-> http://ionicframework.com/docs/api/service/$ionicTabsDelegate/
but there is a problem when you call it immediately after .tabs.push, it throws an error
coze at this time the tab does not yet exists.

therefore i used a little trick and added $timeout with a delay of 50 ms (maybe even lower would work)

the only thing you have to do is track the index of the newly pushed Tab (push reürns not the exact index!)
here my tests:


#4

@bengtler @Auro thank you :blush:


#5

Ha, a little late to the conversation but, yes $ionicTabsDelegate.select() is the way to go. Thanks @Auro and @bengtler for helping out!