我已经设置了两个按钮,可以在点击时切换到其他两个标签,但它不起作用。
这是html代码:
<div ng-controller="TabCtrl">
<uib-tabset class="tabbable">
<uib-tab heading="my tab 0" ng-attr-active="tabs[0].active">
<div class="row">
<a class="btn btn-wide btn-azure" ng-click="go_tab1()">
Go To tab 1
</a>
<a class="btn btn-wide btn-azure" ng-click="go_tab2()">
Go To tab 2
</a>
</div>
</uib-tab>
<uib-tab heading="my tab 1" ng-attr-active="tabs[1].active">
<div class="row">
</div>
</uib-tab>
<uib-tab heading="my tab 2" ng-attr-active="tabs[2].active">
<div class="row">
</div>
</uib-tab>
</uib-tabset>
</div>
这是控制器:
$scope.tabs = [{active: true}, {active: false}, {active: false}];
$scope.go_tab1 = function() {
$scope.tabs[1].active = true;
};
$scope.go_tab2 = function() {
$scope.tabs[2].active = true;
};
答案 0 :(得分:1)
如果添加正确的库
,它将正常工作<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
并注入ui.bootstrap依赖项。
var app = angular.module('app', ['ui.bootstrap']);
var app = angular.module('app', ['ui.bootstrap']);
app.controller('TabCtrl', function($scope) {
$scope.tabs = [{active: true}, {active: false}, {active: false}];
$scope.go_tab1 = function() {
$scope.tabs[1].active = true;
};
$scope.go_tab2 = function() {
$scope.tabs[2].active = true;
};
});
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
<script src="app.js"></script>
<body ng-app="app">
<div ng-controller="TabCtrl">
<uib-tabset class="tabbable">
<uib-tab heading="my tab 0" ng-attr-active="tabs[0].active">
<div class="row">
<a class="btn btn-wide btn-azure" ng-click="go_tab1()">
Go To tab 1
</a>
<a class="btn btn-wide btn-azure" ng-click="go_tab2()">
Go To tab 2
</a>
</div>
</uib-tab>
<uib-tab heading="my tab 1" ng-attr-active="tabs[1].active">
<div class="row">
</div>
</uib-tab>
<uib-tab heading="my tab 2" ng-attr-active="tabs[2].active">
<div class="row">
</div>
</uib-tab>
</uib-tabset>
</div>
</body>