激活时,在<tabset> <tab>上设置ng-model值

时间:2015-08-10 08:06:24

标签: angularjs angular-ui-bootstrap

是否可以在标签上激活时设置$ scope值?

示例:每个都有ng-model =“tabID”的3个选项卡。然后{{tabID}}将是1,2,3,4,具体取决于哪个标签处于活动状态。

2 个答案:

答案 0 :(得分:3)

在标签内点击:

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

在你的javascript(控制器)中:

$scope.activate=function(i)
    {
        $scope.tabID=i;
    }

答案 1 :(得分:0)

您可以使用一个变量来存储选中的选项卡,然后单击更改选项卡值

$scope.changeTab=function(index)
    {
        $scope.selectedtabID=index;

    }
相关问题