我正在使用 angularjs UI bootstrap 来制作标签。我在导航栏中有可以切换到不同选项卡的按钮。带有自己控制器的导航栏嵌套在主控制器内。我也想知道如何在导航栏切换选项卡中制作按钮。
我这里有一个 plunk 或者下面有 html 和 js
<div ng-controller="TabsDemoCtrl">
<header>
<div ng-controller="navbarcontroller">
<div class="navbar-header">
<a class="navbar-brand" >Brand
</a>
</div>
<div class="collapse navbar-collapse" ng-class="!navCollapsed && 'in'">
<ul class="nav navbar-nav navbar-right" style="pointer-events: auto;">
<li>
<!-- this buttons dosnt works -->
<button type="button" class="btn btn-default btn-sm" ng-click="active = 1">Select 1st tab</button>
<button type="button" class="btn btn-default btn-sm" ng-click="active = 2">Select 2nd tab</button>
</li>
</ul>
</div>
</div>
</header>
<p> ----- navbar controller ends here ----- </p>
<hr>
<p> ---- tab controller starts here ------ </p>
<!-- this buttons works -->
<button type="button" class="btn btn-default btn-sm" ng-click="active = 1">Select 1st tab</button>
<button type="button" class="btn btn-default btn-sm" ng-click="active = 2">Select 2nd tab</button>
<uib-tabset active="active">
<uib-tab index="1" heading="Tab1" >
Content 1
</uib-tab>
<uib-tab index="2" heading="Tab1" >
Content 2
</uib-tab>
</uib-tabset>
</div>
这是js文件
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo')
.controller('TabsDemoCtrl', function ($scope, $window) {
})
.controller('navbarcontroller', function ($scope, $window) {
});