以编程方式单击以更改 UI-Bootstrap 中的当前选项卡
Programmatically click to change the current tab in UI-Bootstrap
我想以编程方式激活选项卡,但找不到方法。
这是一个 plunker。
HTML:
<tabset>
<tab id="a1" heading="Static 1">Static 111</tab>
<tab id="a2" heading="Static 2" ng-attr-active="{{nd}}">Static 222</tab>
</tabset>
JS:
$scope.nd = true;
ps:"tabs and their content should not be defined in a js file".
$scope.st = true;
$scope.nd = false;
$scope.goToSecond= function () {
$scope.st = false;
$scope.nd = true;
};
$scope.goToFirst= function () {
$scope.nd = false;
$scope.st = true;
};
哪里
<tabset>
<tab heading="Static title" ng-attr-active="st">"; </tab>
<tab heading="Static 2" ng-attr-active="nd">"; </tab>
</tabset>
我刚刚也在为类似的事情而苦苦挣扎。事实上,我几乎错误地得出了不能以编程方式更改静态选项卡的结论。但他们可以。
<tabset>
<tab heading="Tab 1" ng-attr-active="tabs[0].active">
Tab 1 content
</tab>
<tab heading="Tab 2" ng-attr-active="tabs[1].active">
Tab 2 content
</tab>
<tab heading="Tab 3" ng-attr-active="tabs[2].active">
Tab 3 content
</tab>
</tabset>
<button ng-click="make_tab3_active()">Make Tab 3 Active </button>
在Javascript你需要
$scope.tabs = [{active: true}, {active: false}, {active: false}];
$scope.make_tab3_active = function() {
$scope.tabs[2].active = true;
}
所以只是要指出 - 单个变量是行不通的。它们应该在一个数组中——如上所述。尽管文档给出了类似行的示例,但不清楚,因为 2 个静态选项卡上没有活动,这会让您感到困惑。
我花了很多时间,才找到这个线程的答案:https://github.com/angular-ui/bootstrap/issues/611
我想以编程方式激活选项卡,但找不到方法。
这是一个 plunker。 HTML:
<tabset>
<tab id="a1" heading="Static 1">Static 111</tab>
<tab id="a2" heading="Static 2" ng-attr-active="{{nd}}">Static 222</tab>
</tabset>
JS:
$scope.nd = true;
ps:"tabs and their content should not be defined in a js file".
$scope.st = true;
$scope.nd = false;
$scope.goToSecond= function () {
$scope.st = false;
$scope.nd = true;
};
$scope.goToFirst= function () {
$scope.nd = false;
$scope.st = true;
};
哪里
<tabset>
<tab heading="Static title" ng-attr-active="st">"; </tab>
<tab heading="Static 2" ng-attr-active="nd">"; </tab>
</tabset>
我刚刚也在为类似的事情而苦苦挣扎。事实上,我几乎错误地得出了不能以编程方式更改静态选项卡的结论。但他们可以。
<tabset>
<tab heading="Tab 1" ng-attr-active="tabs[0].active">
Tab 1 content
</tab>
<tab heading="Tab 2" ng-attr-active="tabs[1].active">
Tab 2 content
</tab>
<tab heading="Tab 3" ng-attr-active="tabs[2].active">
Tab 3 content
</tab>
</tabset>
<button ng-click="make_tab3_active()">Make Tab 3 Active </button>
在Javascript你需要
$scope.tabs = [{active: true}, {active: false}, {active: false}];
$scope.make_tab3_active = function() {
$scope.tabs[2].active = true;
}
所以只是要指出 - 单个变量是行不通的。它们应该在一个数组中——如上所述。尽管文档给出了类似行的示例,但不清楚,因为 2 个静态选项卡上没有活动,这会让您感到困惑。
我花了很多时间,才找到这个线程的答案:https://github.com/angular-ui/bootstrap/issues/611