Is there a way to tell which tab that has been selected when using the Bootstrap tabs in Angular UI?
I tried watching the panes array but it deosn't seem to be updated when switching tab. Can one specify a callback function when a tab is selected?
Update with code example.
The code very much follows the example from the Angular UI bootstrap page.
Markup:
<div ng-controller="TabsDemoCtrl"> <tabs> <pane ng-repeat="pane in panes" heading="{{pane.title}}" active="pane.active"> <div ng-include="pane.template"></div> </pane> </tabs> </div>
Controller:
var TabsCtrl = function ($scope) { $scope.panes = [ { title:"Events list", template:"/path/to/template/events" }, { title:"Calendar", template:"/path/to/template/calendar" } ]; };
To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a . tab-pane class with a unique ID for every tab and wrap them inside a <div> element with class . tab-content .
Bootstrap tabs separate data in the same wrappers but different panes. Pills are components placed in pages to speed up browsing. Also, the first step of adding links inside navbar is to apply <ul> element together with class="navbar-nav".
Advertisements. Tabs were introduced in the chapter Bootstrap Navigation Elements. By combining a few data attributes, you can easily create a tabbed interface. With this plug-in you can transition through panes of local content in tabs or pills, even via drop down menus.
Actually this is really simple as each pane
exposes the active
attribute that supports 2-way data binding:
<tabs> <pane ng-repeat="pane in panes" heading="{{pane.title}}" active="pane.active"> {{pane.content}} </pane> </tabs>
and then an active tab can be easily found, for example:
$scope.active = function() { return $scope.panes.filter(function(pane){ return pane.active; })[0]; };
Here is a working plunk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With