[英]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">×</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.