Answers for "onclick add active class in angular"

0

onclick add active class in angular

You can do something like:

<ul class="sub_modules">
  <li (click)="activateClass(subModule)"
      *ngFor="let subModule of subModules"
      [ngClass]="{'active': subModule.active}">
    <a>{{ subModule.name }}</a>
  </li>
</ul>
On The component

activateClass(subModule){
  subModule.active = !subModule.active;    
}
On the Ng class the first property is the class you wanna add and the second is the condition;
Posted by: Guest on March-17-2021
0

onclick add active class in angular

// if needed add a boolean to the array and use it
for(let i = 0; i < this.subModules.length; i++){
	this.subModules[i].active = false;
}

<ul class="sub_modules">
  <li (click)="activateClass(subModule)"
      *ngFor="let subModule of subModules"
      [ngClass]="{'active': subModule.active}">
    <a>{{ subModule.name }}</a>
  </li>
</ul>
On The component

activateClass(subModule){
  subModule.active = !subModule.active;    
}
Posted by: Guest on August-04-2021

Code answers related to "onclick add active class in angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language