简体   繁体   English

打开模态时,如何将其设置为模式的第一个选项卡

[英]How can I set active to first tab on modal when it's opened

Here is my code: 这是我的代码:

<div [id]="id" class="modal fade" tabindex="-1">
  <div class="modal-dialog modal-full">
    <div class="modal-content">
      <div class="modal-header bg-danger">
        <h6 class="modal-title"</h6>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
      <form #editViewForm="ngForm" (ngSubmit)="onSubmit()" id="editViewForm" autocomplete="off">
        <div id="tabs" class="modal-body">
          <!--Tabs Nav-->
          <ul class="nav nav-tabs nav-tabs-highlight mb-0">
            <li class="nav-item"><a href="#bordered-tab1" id="active_tab" class="nav-link active" data-toggle="tab">TAB 1</a></li>
            <li class="nav-item"><a href="#bordered-tab2" class="nav-link" data-toggle="tab">TAB 2</a></li>
            <li class="nav-item"><a href="#bordered-tab3" class="nav-link" data-toggle="tab" style="display:none;">TAB 3</a></li>
            <li class="nav-item"><a href="#bordered-tab4" class="nav-link" data-toggle="tab">TAB 4</a></li>
          </ul>
         </div>
        </form>
    </div>
</div>

How can I set TAB 1 to be opened everytime this modal is opened, in case I close modal on tab3 I want to TAB 1 to be active when I open modal again 如何在每次打开此模式时将TAB 1设置为打开,以防我在tab3上关闭模式时再次打开模式时希望TAB 1处于活动状态

I've tried this: 我已经试过了:

I added on the first tab id like this: active_tab , so I said something like this, when this show is called ( modal is opening ) lets set two classess, show and active, but this unfortnatelly does not work... 我在第一个标签ID上添加了如下代码: active_tab ,所以我说了这样的话,当这个节目被调用时(模式正在打开),我们可以设置两个类show和active,但是不幸的是这行不通...

  show() {
    alert("ok");
    $('#active_tab' + this.id).addClass('active');
    $('#active_tab' + this.id).addClass('show');
    $('#' + this.id).modal('show');

  }

Thanks guys Cheers 谢谢大家的欢呼

Please us [ngClass]="{'active': tabName === 'tab1'}" 请我们[ngClass] =“ {'active':tabName ==='tab1'}”

 <ul class="nav nav-tabs nav-tabs-highlight mb-0">
        <li class="nav-item"><a href="#bordered-tab1" class="nav-link" [ngClass]="{'active': tabName === 'tab1'}" data-toggle="tab">TAB 1</a></li>
        <li class="nav-item"><a href="#bordered-tab2" [ngClass]="{'active': tabName === 'tab2'}" class="nav-link" data-toggle="tab">TAB 2</a></li>
        <li class="nav-item"><a href="#bordered-tab3" [ngClass]="{'active': tabName === 'tab3'}" class="nav-link" data-toggle="tab" style="display:none;">TAB 3</a></li>
        <li class="nav-item"><a href="#bordered-tab4" class="nav-link" data-toggle="tab" [ngClass]="{'active': tabName === 'tab4'}">TAB 4</a></li>
      </ul>

and on the ngOnInt event of the component, set this.tabName = 'tab1' 并在组件的ngOnInt事件上,设置this.tabName ='tab1'

tabName: string;  

ngOnInit() {
  this.tabName = 'tab1'
}

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

相关问题 当模态打开时,如何将焦点设置在模态内部的第一个 TouchableHighlight 组件(或另一个,例如由 ref 给出)上? - How can I set focus on the first TouchableHighlight component (or another one, given by ref for instance) inside the modal when modal is opened? Bootstrap Modal 选项卡在关闭时首先设置为活动状态 - Bootstrap Modal tab first set active when close 如何设置刚刚打开的链接的活动标签 - How to set a tab active of just opened link 打开引导模式时使第一个选项卡成为活动选项卡 - make the first tab the active tab when open a bootstrap modal 当标签处于活动/非活动状态时,如何让标签更改其标题? - How can I make an tab change it's title when it's active/inactive? 关闭模式弹出窗口后,如何重定向到模式弹出窗口中的第一个选项卡? - How can I redirect to first tab in modal popup after I close the modal popup? 当我有静态选项卡angularjs UI时如何使第一个选项卡处于活动状态 - how to to make first tab active when I have static tab angularjs UI 打开模态时,如何将按钮聚焦在模态内 - How do I focus a button inside modal when the modal is opened 如何将引导选项卡设置为活动状态? - How do I set a bootstrap tab active? 在Tabpanel中使用引导模式来设置活动标签 - Using bootstrap modal with Tabpanel to set active tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM