angularjs - How to set bootstrap active tab on refresh in Angular JS -


i creating tabs as:

 <tabset class="content-tabset no-margin"> <tab ng-repeat="t in t.values" heading="{{t.name}}" active="t.active">   //other stuff </tab> </tabset> 

now within other stuff have button when clicks updates row , refreshes part. when refresh happens resets tab on. if tab 2 , click on button, panel refreshes , come on tab 1. how can prevent this?

use localstorage. set on selecting tab. boolean value of active state current tab use ng-init.

<tabset class="content-tabset no-margin">   <tab      ng-repeat="t in t.values"      heading="{{t.name}}"      ng-init="isactive = isactivetab(t.name, $index)"     active="isactive"     select="setactivetab(t.name)">     //other stuff   </tab> </tabset> 

and in controller

$scope.setactivetab = function( activetab ){     localstorage.setitem("activetab", activetab); };  $scope.getactivetab = function(){     return localstorage.getitem("activetab"); };  $scope.isactivetab = function( tabname, index ){     var activetab = $scope.getactivetab();     return ( activetab === tabname || ( activetab === null && $index === 0 ) ); }; 

note: since t has no unique id tabs, names should unique detect active tab correctly.

see example jsfiddle.