我正在使用angularjs UI引導來製作選項卡。我在導航欄中有切換到不同選項卡的按鈕。具有自己的控制器的navbar嵌套在主控制器內。我想知道如何在導航欄切換選項卡中製作按鈕。ng-Click影響到不同的控制器
我有一個普拉克here 或低於
<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>
HTML和JS這是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) {
});
它看起來像你的'navbarController'實際上結束上述兩行,你還記下。 – Pytth
你能否給我們提供一個[最小,完整和可驗證的例子](http://stackoverflow.com/help/mcve)?也許一個jsfiddle或plunker ... – lealceldeiro
@Pytth是這只是爲了表明結束。 – Pujan