Reputation: 1823
I want to add a class to element with a particular id in Angular 2.
In JavaScript, here is how it's done, but I don't have an idea on how to do it in Angular2.
document.getElementById("MyElement").className += " active";
So far, I have this:
<div id="1" [class.active]="conditionIsHere">div 1</div>
<div id="2" [class.active]="conditionIsHere">div 2</div>
Upvotes: 3
Views: 3417
Reputation: 658067
<div id="1" [class.active]="activeId == 1" (click)="activeId=1">div 1</div>
<div id="2" [class.active]="activeId == 2" (click)="activeId=2">div 2</div>
class MyComponent {
activeId:number;
}
Upvotes: 4