简体   繁体   中英

angularJS add a class + set default for bootstrap Tabs

I have an angular tabbable here. How can I set default tab? + add a class to specific tab?

http://plnkr.co/edit/FPMf8i

eg I want the tab 2 to be slected by default. Then tab 1 have a specific class.

I tried

 element.children[1].addClass('test');
 element[0].children[0].addClass('test');
 element[0].addClass('test');

but keep getting an error

Can't use jquery has to be library already there.

Add an initial value for your ng-model , then use ng-class to set dynamic classes

Plnkr

http://plnkr.co/edit/udxAT0?p=preview

View

<div ng-controller="TabsCtrl">
  <div class="tabbable" ng-model="currentTab">
    <div class="tab-pane" ng-class="{'special-class': currentTab == 1}" title="1" value="1">
      Content 1
    </div>
    <div class="tab-pane" title="2" value="2">
      Content 2
    </div>
  </div>
</div>

Controller

var app = angular.module('plunker', ['bootstrap']);

app.controller("TabsCtrl", function($scope) {
  $scope.currentTab = 1;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM