简体   繁体   English

如何将活动类应用于Bootstrap Tab UI

[英]How to apply active class to bootstrap Tab ui

I've a bootstrap ui tab angularjs directive that sets the first tab as an active tab by default. 我有一个引导ui选项卡angularjs指令,默认情况下将第一个选项卡设置为活动选项卡。 Problem here is, if you are in tabs, other than the first tab, and try refreshing the page, since the default active class is on first tab, on refresh it shows first tab as active. 这里的问题是,如果您位于除第一个选项卡之外的其他选项卡中,并尝试刷新页面,因为默认的活动类位于第一个选项卡上,因此在刷新时它将第一个选项卡显示为活动状态。 However the content shown will be from the correct tab. 但是,显示的内容将来自正确的选项卡。 Bootstrap directive: Bootstrap指令:

var configDirectives = angular.module('configDirectives', []);

configDirectives.directive('configTabs', function(){
  return{
  restrict:'A',
  template: '\
  <ul class="nav nav-tabs">\
    <li class="active"><a href="#categories" data-    toggle="tab">categories</a></li>\
<li><a href="#uploadassets" data-toggle="tab">upload assets</a></li>\
<li><a href="#" data-toggle="tab">lorem ipsum</a></li>\
  </ul>'
}});

My question is : can we set this active class dynamically rather than hard-coding it in first li element? 我的问题是:我们可以动态设置此活动类,而不是在第一个li元素中对其进行硬编码吗?

Use ng-class with custom variable: 将ng-class与自定义变量一起使用:

ng-class="{'active' : selectedType == 'categories'}"

And ng-click to select active tab (inside your a href or div or whatever): 然后ng点击以选择活动标签(在href或div或其他内容内):

ng-click="selectedTab = 'categories'"

Add 'selectedType' to the directive scope 将“ selectedType”添加到指令范围

scope: { selectedType: '=' } 范围:{selectedType:'='}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM