Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell which bootstrap tab is selected in Angular-UI

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" }   ]; }; 
like image 946
John P Avatar asked Mar 28 '13 15:03

John P


People also ask

How do I toggle between tabs in bootstrap?

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 .

How do bootstrap tabs work?

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".

What is Bootstrap Tab plugin?

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.


1 Answers

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

like image 98
pkozlowski.opensource Avatar answered Oct 02 '22 05:10

pkozlowski.opensource