我在尝试使用uib-tabset插件时遇到了一个问题,好吧,插件工作正常,但我需要在特定的东西中使用它。 问题:如何将Tabs标题与标签内容分开。
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function ($scope, $window) { $scope.setActiveTab = function(index){
$scope.activeTab = index;
}
});
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.1.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div ng-app="ui.bootstrap.demo">
<div ng-controller="TabsDemoCtrl">
<div class="some-tabs-header-holder">
<uib-tabset active="active" vertical="false" >
<uib-tab index="0" heading="Tab 1"><!-- not needed tab 1 content--></uib-tab>
<uib-tab index="1" heading="Tab 2"><!-- not needed tab 2 content--></uib-tab>
</uib-tabset>
<div>
<div class="the-tabs-content-holder">
<div id="tab1" class="tab1-content">tab 1 content</div>
<div id="tab2" class="tab2-content">tab 2 content</div>
</div>
</div>
</div>
我只需要在选中标签时显示“the-tabs-content-holder”div中的内容
答案 0 :(得分:4)
您可以为每个标签附加select
事件处理程序并使用ng-if
指令,以便根据tab
的值显示$scope.activeTab
内容
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function ($scope, $window) {
$scope.activeTab=1;
$scope.setActiveTab = function(index){
$scope.activeTab = index;
}
});
&#13;
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.1.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div ng-app="ui.bootstrap.demo">
<div ng-controller="TabsDemoCtrl">
<div class="some-tabs-header-holder">
<uib-tabset active="active" vertical="false" >
<uib-tab select="setActiveTab(1)" index="0" heading="Tab 1"><!-- not needed tab 1 content--></uib-tab>
<uib-tab select="setActiveTab(2)" index="1" heading="Tab 2"><!-- not needed tab 2 content--></uib-tab>
</uib-tabset>
<div>
<div class="the-tabs-content-holder">
<div id="tab1" ng-if="activeTab==1" class="tab1-content">tab 1 content</div>
<div id="tab2" ng-if="activeTab==2" class="tab2-content">tab 2 content</div>
</div>
</div>
</div>
&#13;
答案 1 :(得分:1)
index
设置所选标签的ng-click="setActiveTab(0)"
。$scope.activeTab
ng-if
的值显示标签内容div
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function($scope, $window) {
$scope.activeTab = 0;
$scope.setActiveTab = function(index) {
$scope.activeTab = index;
}
});
&#13;
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.1.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div ng-app="ui.bootstrap.demo">
<div ng-controller="TabsDemoCtrl">
<div class="some-tabs-header-holder">
<uib-tabset active="active" vertical="false">
<uib-tab index="0" heading="Tab 1" ng-click="setActiveTab(0)">
<!-- not needed tab 1 content-->
</uib-tab>
<uib-tab index="1" heading="Tab 2" ng-click="setActiveTab(1)">
<!-- not needed tab 2 content-->
</uib-tab>
</uib-tabset>
<div>
<div class="the-tabs-content-holder">
<div id="tab1" class="tab1-content" ng-if="activeTab == 0">tab 1 content</div>
<div id="tab2" class="tab2-content" ng-if="activeTab == 1">tab 2 content</div>
</div>
</div>
</div>
&#13;