【发布时间】:2017-04-10 23:09:34
【问题描述】:
我试图在单击特定选项卡时禁用所有其他选项卡。意味着,假设最初在应用程序运行时,tab1 显示为默认值。之后,如果我选择 tab2,所有其他选项卡都应该被禁用,只有在我们点击取消按钮时才会重新启用。
HTML 代码:
<tabset>
<tab
ng-repeat="t in tabs"
heading="{{t.heading}}"
select="go(t.route)"
active="t.active">
</tab>
</tabset>
<div ui-view></div>
JS代码:
var app = angular.module("routedTabs", ["ui.router", "ui.bootstrap"]);
app.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/main/tab1");
$stateProvider
.state("main", { abtract: true, url:"/main", templateUrl:"main.html" })
.state("main.tab1", { url: "/tab1", templateUrl: "tab1.html" })
.state("main.tab2", { url: "/tab2", templateUrl: "tab2.html" })
.state("main.tab3", { url: "/tab3", templateUrl: "tab3.html" })
.state("main.tab4", { url: "/tab4", templateUrl: "tab4.html" });
});
$scope.go = function(route){
$state.go(route);
};
$scope.active = function(route){
return $state.is(route);
};
$scope.tabs = [
{ heading: "Tab1", route:"main.tab1", active:false },
{ heading: "Tab2", route:"main.tab2", active:false },
{ heading: "Tab3", route:"main.tab3", active:false },
{ heading: "Tab4", route:"main.tab4", active:false },
];
$scope.$on("$stateChangeSuccess", function() {
$scope.tabs.forEach(function(tab) {
tab.active = $scope.active(tab.route);
});
});
【问题讨论】:
-
你能创建一个小提琴/plunker吗?
-
plunker 我已经创建了 plunker
-
所以取消按钮是在当前标签内还是在所有标签外?
-
它将在当前选项卡中。当我单击当前选项卡上的取消按钮时。然后所有选项卡都将启用。
-
有uib-tab settings
disable属性可以用来满足你的需要
标签: angularjs angular-ui-router