here is my code examples.
In my case toggle class works for every li
element
<ul class="nav nav-pills pull-right">
<li *ngFor="let x of nav" class="presentation" (click)="active = !active" [ngClass]="toggleClass()">
<a href="#">{{x.menu}} </a>
</li>
</ul>
js
export class AppComponent {
active = false;
nav = NAVIGATION;
//Toggle Class
toggleClass(){
if(this.active){
return 'active';
} else {
return '';
}
}
With following code, you don't need to write typescript code,
<ul class="nav nav-pills pull-right">
<li *ngFor="let x of nav;let i=index"
class="presentation"
(click)="isClicked=i"
[class.active]="isClicked==i">
<a href="#">{{x.menu}}</a>
</li>
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With