Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs UI bootstrap dynamically select among static tabs not working

I have three static tabs and a button that with ng-click="selectThirdTab()"

<div ng-controller="Ctrl">
        <input type="button" value="Select third tab" ng-click="selectThirdTab()" />
        <tabset justified="true">
            <tab heading="First" active="isFirstActive"></tab>
            <tab heading="Second" active="isSecondActive"></tab>
            <tab heading="Third" active="isThirdActive"></tab>
        </tabset>
</div>

function "selectThirdTab" is as follows:

$scope.selectThirdTab = function () {
    $scope.isThirdActive = true;
}

the plunker is here: Plunker

Initially the first tab is selected, you click on the button and the result is the the third button selected. Now if you select an other tab and then click on the button "Select third tab" again, then the third button does not get selected. What's wrong?

like image 934
Christian Avatar asked Jun 11 '14 08:06

Christian


3 Answers

Or you can go that way:

angular.module('plunker', ['ui.bootstrap']);
var Ctrl = function ($scope, $timeout) {
    $scope.isActive = [{active:true},{active:false},{active:false}];
    $scope.selectThirdTab = function () {
          $scope.isActive[2].active = true;
    }
}

and in html

    <tabset justified="true">
        <tab heading="First" active="isActive[0].active"></tab>
        <tab heading="Second" active="isActive[1].active"></tab>
        <tab heading="Third" active="isActive[2].active"></tab>
    </tabset>
like image 157
Der Zinger Avatar answered Sep 18 '22 22:09

Der Zinger


Only one tab may be active at a time:

$scope.selectThirdTab = function () {
    $scope.isThirdActive = true;
    $scope.isSecondActive=false;
    $scope.isFirstActive=false;
}
like image 38
pixelbits Avatar answered Sep 21 '22 22:09

pixelbits


You just replace the following code

   $scope.selectThirdTab = function () {
      $scope.isThirdActive = true;
   }

by

$scope.selectThirdTab = function () {
   $scope.isFirstActive=false;
   $scope.isSecondActive=false;
   $scope.isThirdActive = true;
}

Hope it will help you.

I guess this example can help you. http://plnkr.co/edit/7XvmsjAZ1DrA0K4F6kiw?p=preview

like image 22
getty_advaanz Avatar answered Sep 19 '22 22:09

getty_advaanz