I have nav, Twitter Bootstrap, inside one of the tabs (#B ..), I have an image that clicks on it in another tab (#C ..).
I can change this tab, but I cannot, that the new tab is (#C ..)set to active. And where is this image tab (#B ..)set to deactivate. (e.g. removeClass is active)
<ul class="nav nav-tabs">
<li class="nav active"> <a [attr.href]="'#A' + cObj" data-toggle="tab"> Info </a></li>
<li class="nav"> <a [attr.href]="'#B' + cObj" data-toggle="tab"> Info </a></li>
<li class="nav"> <a [attr.href]="'#C' + cObj" data-toggle="tab"> Info </a></li>
</ul>
<div class="tab-pane fade" [id]="'B' + cObj">
..
<a [attr.href]="'#C' + cObj" data-toggle="tab">
<img...>
..
I tried [class.active] =" false "using it in various ways, for example [ '#B' + cObj.class.active] =" false ", but I can’t, anything that could help me.
I would like to be able to activate and deactivate a tab, switching from one to the other, sorry for my poor English. Hope you understand my question.
: .
, :
<ul class="nav nav-tabs">
<li class="nav active" [id]="'IDA' + contadorObjet.name" [class.active]="testLocation1() == ('A' + contadorObjet.name) || '10'" > <a [attr.href]="'#A' + contadorObjet.name" data-toggle="tab"> Info </a></li>
<li class="nav" [id]="'IDB' + contadorObjet.name" [class.active]="testLocation1() == 'B' + contadorObjet.name"> <a [attr.href]="'#B' + contadorObjet.name" data-toggle="tab"> Info </a></li>
<li class="nav" [id]="'IDC' + contadorObjet.name" [class.active]="testLocation1() == 'C' + contadorObjet.name"> <a [attr.href]="'#C' + contadorObjet.name" data-toggle="tab"> Info </a></li>
</ul>
: '10 ' ID
<a [attr.href]="'#C' + contadorObjet.name" data-toggle="tab"
#elem (click)="testLocationAct(elem.href, 'IDB' + contadorObjet.name)" >
testLocation1():string{
//alert(document.activeElement.toString().split(/#(.+)?/)[1]);
return document.activeElement.toString().split(/#(.+)?/)[1];
}
testLocationAct(test: any, test1: any){
document.getElementById(test1).classList.remove('active');
document.activeElement = test;
}
UPDATE:
. -
Plunker
, , , , ( ).
<div class="container" *ngFor="#contadorObjeto of contadorObjetos ; #contadorObjetoI = index" nginit="test='#' id=10">
<ul class="nav nav-tabs">
<li class="nav active" [id]="'IDA' + contadorObjeto.name" ([class.active])="testLocation1() == ('A' + contadorObjeto.name) || '10'"> <a [attr.href]="'#A' + contadorObjeto.name" data-toggle="tab"> Info </a></li>
<li class="nav" [id]="'IDB' + contadorObjeto.name" ([class.active])="testLocation1() == 'B' + contadorObjeto.name"> <a [attr.href]="'#B' + contadorObjeto.name" data-toggle="tab"> Info </a></li>
<li class="nav" [id]="'IDC' + contadorObjeto.name" ([class.active])="testLocation1() == 'C' + contadorObjeto.name"> <a [attr.href]="'#C' + contadorObjeto.name" data-toggle="tab"> Info </a></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" [id]="'A' + contadorObjeto.name">Content inside tab A
{{ contadorObjeto.name }}
</div>
<div class="tab-pane fade in " [id]="'B' + contadorObjeto.name">Content inside tab B
<a [attr.href]="'#C' + contadorObjeto.name" data-toggle="tab" #elem (click)="testLocationAct(elem.href, 'IDB' + contadorObjeto.name)" >
<img class="img-responsive"
height = "230" width = "230"
src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Free_logo.svg/200px-Free_logo.svg.png" />
</a>
</div>
<div class="tab-pane fade in " [id]="'C' + contadorObjeto.name">Content inside tab C
</div>
</div>
</div>
testLocation1():string{
//alert(document.activeElement.toString().split(/#(.+)?/)[1]);
return document.activeElement.toString().split(/#(.+)?/)[1];
}
testLocationAct(test: any, test1: any){
liNavID = "ID" + test.toString().split(/#(.+)?/)[1];
document.getElementById(test1).classList.remove('active');
document.getElementById(liNavID).classList.add('active');
//console.log(liNavID);
}
, , . 2 .
.