gpt4 book ai didi

javascript - 如何在 angular-ui 中选择一个选项卡? ( Angular )

转载 作者:数据小太阳 更新时间:2023-10-29 05:14:54 24 4
gpt4 key购买 nike

我想选择最后一个选项卡,知道怎么做吗?只有 ng-repeat 里面的选项卡可以选择,我不会用 ng-repeat,没有 ng-repeat 怎么办?

这是工作代码:http://plnkr.co/edit/ZJNaAVDBrbr1JjooVMFj?p=preview

<!doctype html>
<html ng-app="ui.bootstrap.demo">

<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

<div ng-controller="TabsDemoCtrl">
<p>Select a tab by setting active binding to true:</p>
<p>
<button type="button" class="btn btn-default btn-sm" ng-click="tabs[0].active = true">Select second tab</button>
<button type="button" class="btn btn-default btn-sm" ng-click="tabs[1].active = true">Select third tab</button>
<button type="button" class="btn btn-default btn-sm" ng-click="tabs[3].active = true">SELECT LAST TAB!!!</button>
</p>
<p>
<button type="button" class="btn btn-default btn-sm" ng-click="tabs[1].disabled = ! tabs[1].disabled">Enable / Disable third tab</button>
</p>
<hr />

<uib-tabset>
<uib-tab heading="Static title">Static content</uib-tab>
<uib-tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disable="tab.disabled">
{{tab.content}}
</uib-tab>
<uib-tab heading="How to select this tab???">nico</uib-tab>
</uib-tabset>
</div>

<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 type="text/javascript">
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function($scope, $window) {
$scope.tabs = [{
title: 'Dynamic Title 1',
content: 'Dynamic content 1'
}, {
title: 'Dynamic Title 2',
content: 'Dynamic content 2',
disabled: true
}];
});
</script>

</body>

</html>

最佳答案

我所做的只是初始化一个新对象来保存您的新选项卡,并更改您在按钮中的引用。它解决了您的问题,但我不知道它是否是您想要的架构。

以下是亮点:

  $scope.separateTab = {
title: 'How to select this tab???',
content: 'Dynamic content 2'
};

<uib-tab heading="{{separateTab.title}}" active="separateTab.active">nico</uib-tab>

<button type="button" class="btn btn-default btn-sm" ng-click="separateTab.active = true">SELECT LAST TAB!!!</button>

这是 plnkr

关于javascript - 如何在 angular-ui 中选择一个选项卡? ( Angular ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34599431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com