I am trying to use angular Renderer2 to add and remove a class in HTML template. Here I am facing the difficulties:
- to add the class once component will load
- Only the selected item should have the class
I have created a demo in stackblitz. Please click here to see code.
Thank you.
<div class="tabs">
<a href="#" (click)="selectTab($event)">Tab 1 </a>
<a href="#" (click)="selectTab($event)">Tab 2 </a>
<a href="#" (click)="selectTab($event)">Tab 3</a>
</div>
constructor(private render:Renderer2){}
selectTab(event:any) {
this.render.addClass(event.target,"test");
}