5

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?

1 Answer 1

5

You are using an old version of Angular UI Bootstrap (0.14.3)

<uib-tabset>
  <uib-tab heading="First" active="selected == 1">
    First data
  </uib-tab>
  <uib-tab heading="Second" active="selected == 2">
    Second data 
  </uib-tab>
</uib-tabset>

See documentation for more info (http://angular-ui.github.io/bootstrap/versioned-docs/0.14.3/#/tabs)

Also a working Plunkr (http://plnkr.co/edit/qAbUtv06ck64JCf8JaKp?p=preview)

PS. Your code above works for versions 1.2.0 above. If you have the option to upgrade versions, you can do it as well :)

Sign up to request clarification or add additional context in comments.

1 Comment

@DevinMcQueeney yes, this won't work. as you can see it should only work for his specific version Angular UI Bootstrap (0.14.3) which is NOT compatble with Angular 1.5+

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.