uib-tabset动态索引不起作用

时间:2017-07-19 05:21:00

标签: angularjs angular-ui-bootstrap angular-animations uib-tabset

我正在尝试动态设置uib-tabs。 我的意思是我已经在html中编写了所有代码,并且只能动态地查看代码。我在这里简化了这个例子。我将index =“1”给了第一个标签,但它没有按要求工作。

<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.0.0.js"></script>


<div ng-app="uib-tabs.demo" ng-controller="TabsDemoCtrl">
  <!--I have given index 1 to Static tab still it's at index 0.
  actually in my code I am calling a function from index which returns the index somethiing like this
  
  <uib-tab index="findMyIndex('static')" heading="Static title">Static content</uib-tab>-->
  <uib-tabset active="active">
    <uib-tab index="1" heading="Static title">Static content</uib-tab>
    <uib-tab index="0" select="alertMe()">
      <uib-tab-heading>
        <i class="glyphicon glyphicon-bell"></i> Alert!
      </uib-tab-heading>
      I've got an HTML heading, and a select callback. Pretty cool!
    </uib-tab>
  </uib-tabset>
</div>
  
<script>
angular.module('uib-tabs.demo', ['ngAnimate', 'ui.bootstrap'])
.controller('TabsDemoCtrl', function ($scope, $window) {
  $scope.tabs = [
    { title:'Dynamic Title 1', content:'Dynamic content 1' },
    { title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
  ];

  $scope.alertMe = function() {
    setTimeout(function() {
      $window.alert('You\'ve selected the alert tab!');
    });
  };

  $scope.model = {
    name: 'Tabs'
  };
});
</script>

先谢谢。

我不能对标签使用ng-repeat,因为它们不同而我的HTML文件太大

1 个答案:

答案 0 :(得分:0)

您可以使用 $index 动态设置标签索引,并使用 ng-repeat 生成标签集。

<uib-tabset active="active">
  <uib-tab  index="$index" ng-repeat="tab in tabs" >
    <uib-tab-heading>{{tab.title}}</uib-tab-heading>
    {{tab.content}}
  </uib-tab>
</uib-tabset>