Set ng-model value on <tabset> <tab> when active - angularjs

Is it possible to set a $scope value on a tab when its active?
Example: 3 tabs with ng-model="tabID" on each. Then {{tabID}} would be either 1,2,3,4 depending on what tab is active.

Put ng-click inside tab:
<tabset>
<tab ng-model="tabID" ng-click="activate(1)">
<tab-heading><i class="fa fa-bell"></i> First tab</tab-heading>
<tab-content>
fixed tab content
</tab-content>
</tab>
<tab ng-model="tabID" ng-click="activate(2)">
<tab-heading><i class="fa fa-bell"></i> Second tab</tab-heading>
<tab-content>
Content
</tab-content>
</tab>
<tab ng-model="tabID" ng-click="activate(3)">
<tab-heading><i class="fa fa-bell"></i> Third Tab</tab-heading>
<tab-content>
content
</tab-content>
</tab>
</tabset>
In your javascript (controller):
$scope.activate=function(i)
{
$scope.tabID=i;
}

You can have one variable which stores which tab is selected and onclick change the tab value
$scope.changeTab=function(index)
{
$scope.selectedtabID=index;
}

Related

angular ui tabs active based on ui-router state

I'm getting this error:
Error: [$compile:nonassign] Expression '$state.current.name==='admin.adminDetails'' used with directive 'tab' is non-assignable!
Trying to activate tabs based off of url:
<tabset direction="right" class="tabbable">
<tab heading="Details" ui-sref="admin.details" active="$state.current.name === 'admin.details'">
<div ui-view="adminDetails"></div>
</tab>
<tab heading="Resources" ui-sref="admin.resources" active="$state.current.name==='admin.resources'">
<div ui-view="adminResources"></div>
</tab>
</tabset>
I'm doing it this way so when the url is /admin/resources then the tab will open on the resources tab and same with the details.
Any insight into this error?
You could try using ui-sref-active="active" instead og active.
This applies the class "active" to the element.
Should be used alongside with ui-sref. Docs

Angular-Ui Bootstrap TabSet running on-select

I'm using Angular-Ui Bootstrap Tabset for AngularJS. I have 8 different tabs and all of them run a function when clicked. The activated tab is defined on the controller based on the object properties. The code is like this:
<tabset ng-if="paginaPronta">
<tab heading="Histórico" active="activeTabs.historico" disabled="beforeNew" select="tabHistorico('html')">
<div ng-include="includes.historico" class="row padding0"></div>
</tab>
<tab heading="Pedido" active="activeTabs.pedido" select="tabPedido('html')">
<div ng-include="includes.pedido" class="row padding0"></div>
</tab>
<tab heading="Documentos" active="activeTabs.documentos" disabled="beforeNew" select="tabDocumentos('html')">
<div ng-include="includes.documentos" class="row padding0"></div>
</tab>
<tab heading="Posse" active="activeTabs.posse" disabled="beforeNew" select="tabPosse('html')">
<div ng-include="includes.posse"></div>
</tab>
<tab heading="Despesas" active="activeTabs.despesas" disabled="beforeNew" select="tabDespesas('html')">
<div ng-include="includes.despesas" class="row padding0"></div>
</tab>
<tab heading="Faturação" active="activeTabs.faturacao" select="tabFaturacao('html')">
<div ng-include="includes.faturacao" class="row padding0"></div>
</tab>
<tab heading="Anexos" select="tabAnexos('html')">
<div ng-include="includes.anexos" class="row padding0"></div>
</tab>
<tab heading="Relatório" active="activeTabs.relatorio" disabled="beforeNew" select="tabRelatorio('html')">
<div ng-include="includes.relatorio"></div>
</tab>
</tabset>
Everything works fine at beginning but, when I change the location to navigate to another page, all 8 tab functions are called (tabHistorico(), tabPedido(), tabPosse()...)
I'm not calling the functions in any other place, I put the 'html' in every function and them made a console.log('tabHistorico: ' + phrase) on the controller and it gets printted tabHistorico: html. So, I know that all tabs are activated, I can't figure out why...

How do I set the tabindex (or any other attribute) of an AngularUI Boostrap tab heading link?

I'm using AngularUI Bootstrap like this to create a tabset:
...
<tabset>
<tab heading="First Tab">
<div>First Content Here</div>
</tab>
<tab heading="Second Tab">
<div>Second Content Here</div>
</tab>
</tabset>
...
The code that is output to the page looks like this:
...
<ul class="...">
<li ng-class="..." heading="First Tab" class="...">
<a href ng-click="select()" tab-heading-transclude class="ng-binding">
First Tab
</a>
</li>
<li ng-class="..." heading="Second Tab" class="...">
<a href ng-click="select()" tab-heading-transclude class="ng-binding">
Second Tab
</a>
</li>
</ul>
<div class="tab-content">
<!-- tab contents here -->
</div>
...
The problem I have, is the heading links can't be selected via the keyboard because they're missing a tabindex. Obviously, I can't just add that in because angular is creating the filler HTML for the list, and adding a tabindex to the tab element next to the heading attribute just adds it to the li and not the a tag where it needs to be.
Is there a way to define a tabset and also pass in an attribute like a tabindex to be placed on the navigation (heading) links?

angular ui-bootstrap on the tabs how to add href

<tabset>
<tab heading="{{nav.label}}" ng-repeat="nav in vm.data" href="{{nav.url}}">
<tabset class="subnav">
<tab ui-href="{{item.state}}" href="{{item.state}}" heading="{{item.label}}" ng-repeat="item in nav.items">
</tab>
</tabset>
</tab>
</tabset>
I want to add href, but you can not click!
I used angular-ui-bootstrap and angular-route!
What can I do?
You are making a mistake it isn't 'ui-href' but "ui-sref" and give a state name to it.
sref is for "state reference".

Nested bootstrap tabsets

I'm trying to get nested tabsets. But there's a problem - the nested tabset doesn't work because of TypeError: Cannot read property '$parent' of undefined
You can see it here:
http://plnkr.co/edit/xU9RibIL9k1D3m4GwB5z?p=preview
The html part (most important, controller is empty)
<tabset>
<tab heading="normal">
<div>Content 1</div>
</tab>
<tab heading="nested">
<div>
<tabset>
<tab heading="Nested One">
<div>Nested Content 1</div>
</tab>
<tab heading="Nested Two">
<div>Nested Content 2</div>
</tab>
</tabset>
</div>
</tab>
</tabset>
(And no, I can't use ng-view and routing - because I don't want to lost contents of tabs when switched back - routing reloads tab content)

Resources