gpt4 book ai didi

javascript - Angular ui引导选项卡组件: how to get the content of a tab when the tab is active not clicked

转载 作者:行者123 更新时间:2023-11-27 23:19:12 25 4
gpt4 key购买 nike

我在我的 angularjs 项目中使用 ui bootstrap 'tabs' 组件。它在名为 tab.html 的文件中定义。定义代码如下:

<uib-tabset class="product-tab-bar">
<uib-tab ng-repeat="tab in tabs" active="tab.active" ui-sref="{{tab.action}}" disable="tab.disabled" class="product-tab">
<uib-tab-heading>
<span class="{{tab.icon}}"></span> {{tab.title}}
</uib-tab-heading>
<div ui-view></div>
</uib-tab>
</uib-tabset>

选项卡在 Controller 中定义,它们是:

.controller('myController', function () {

$scope.tabs = [
{title: "tab1", action:".tab1" , icon: "icon-tab1", active: false},
{title: "tab2", action:".tab2" , icon: "icon-tab2", active: true},
{title: "tab3", action:".tab3" , icon: "icon-tab3", active: false}
]
});

各州的定义是:

.state('tab', {
url: '/tab',
templateUrl: 'tab.html'
})
.state('tab.tab1', {
url: '/tab1',
templateUrl: 'tab1.html',
})
.state('tab.tab2', {
url: '/tab2',
templateUrl: 'tab2.html',
})
.state('tab.tab3', {
url: '/tab3',
templateUrl: 'tab3.html',
})

当您单击该选项卡时,状态将会更改。现在我的问题是,当我第一次加载 tab.html 时,选项卡“tab2”被激活,但 tab2 的内容未加载

你可以看到如下:

fist load tab2 content

我需要点击'tab2',状态会改变,内容会加载

你可以看到如下:

after click tab2 content

那么有什么方法当我第一次加载tab.html时,可以加载'tab2'的内容或者如何激活'tab2'的状态?

最佳答案

您实际上必须导航到该州。

var activeTab;
for(var i = 0; i < $scope.tabs.length; i++) {
if($scope.tabs[i].active) {
activeTab = $scope.tabs[i];
break;
}
}

if(activeTab) {
$state.go(activeTab.action);
}

JSFiddle 可用 here .

关于javascript - Angular ui引导选项卡组件: how to get the content of a tab when the tab is active not clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35534608/

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