Programmatically click to change the current tab in UI-Bootstrap

I want to activate tabs programmatically, but cannot find a way.

Here is this plunker . HTML:

<tabset>
<tab id="a1" heading="Static 1">Static 111</tab>
<tab id="a2" heading="Static 2" ng-attr-active="{{nd}}">Static 222</tab>
</tabset>

JS:

$scope.nd = true;

ps: "tabs and their contents should not be defined in the js file".

+4
source share
2 answers
        $scope.st = true;
        $scope.nd = false;

       $scope.goToSecond= function () {
            $scope.st = false;
            $scope.nd = true;
        };
        $scope.goToFirst= function () {
            $scope.nd = false;
            $scope.st = true;
        };

Where

<tabset>
 <tab heading="Static title" ng-attr-active="st">"; </tab>
 <tab heading="Static 2" ng-attr-active="nd">"; </tab>
</tabset>
+1
source

I just fought for something like that. In fact, I almost mistakenly concluded that static tabs cannot be changed programmatically. But they can be.

 <tabset>
        <tab heading="Tab 1"  ng-attr-active="tabs[0].active">
              Tab 1 content
        </tab>
        <tab heading="Tab 2"  ng-attr-active="tabs[1].active">
              Tab 2 content
        </tab>
        <tab heading="Tab 3"  ng-attr-active="tabs[2].active">
              Tab 3 content
        </tab>
 </tabset>
 <button ng-click="make_tab3_active()">Make Tab 3 Active </button>

In javascript you need

$scope.tabs = [{active: true}, {active: false}, {active: false}];
$scope.make_tab3_active = function() {
    $scope.tabs[2].active = true;
}

- . - . , , 2 , .

, : https://github.com/angular-ui/bootstrap/issues/611

+8

All Articles