gpt4 book ai didi

javascript - Angular Bootstrap 选项卡 - 选择页面加载中调用的函数

转载 作者:数据小太阳 更新时间:2023-10-29 04:19:28 29 4
gpt4 key购买 nike

我有以下格式的 Angular Bootstrap 选项卡。 (见 plunker)

select 函数应该在选项卡被选中时触发。但奇怪的是,当页面加载时,第一个选项卡的选择功能被触发。 (打印选项卡选择动态标题 1 加载..)

"http://plnkr.co/edit/vyOOhCdIl7s1Wvou7Dr9?p=preview"

angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function ($scope) {
$scope.tabs = [
{ title:'Dynamic Title 1', content:'Dynamic content 1' },
{ title:'Dynamic Title 2', content:'Dynamic content 2' },
{ title:'Dynamic Title 3', content:'Dynamic content 3' }
];

$scope.tabSelect = function(title){
console.log("tab selected "+title);
};

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="TabsDemoCtrl">
<tabset>
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disable="tab.disabled" select="tabSelect(tab.title)">
{{tab.content}}
</tab>
</tabset>
</div>
</body>
</html>

最佳答案

像这样将您的选择更改为 ng-click:

<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" ng-click="tabSelect(tab.title)">

关于javascript - Angular Bootstrap 选项卡 - 选择页面加载中调用的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30293887/

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