I have a webpage with two angular ui tabs. I adding a new button into this page and I want to add this button-click behavior: when the button clicked, swap the tab to the other tab.
For example:
- If the current active tab is "first" - make the "second" tab to be active.
- if the current active tab is "second" - make the "first" tab to be active.
Here is my (not) working example: http://plnkr.co/edit/2ajxz7oGYmF8oPlHc8kc
<uib-tabset type="pills" active="selected">
<uib-tab heading="First" index="1">
First data
</uib-tab>
<uib-tab heading="Second" index="2">
Second data
</uib-tab>
</uib-tabset>
I'm pretty sure that one of my problem is depending on the active="selected"
segment. This since I'm expecting that the variable will be placed on $scope
, while it's running on separated scope (of the tab-set). I tried to pass this issue with workaround by change this segment to active="$parent.$parent.selected"
- with no success.
So, the main problem is the swap()
function:
$scope.swap = function() {
alert($scope.selected);
if ($scope.selected == 1)
$scope.selected = 2;
else
$scope.selected = 1;
}
How should I do it right?