I'm running into a problem with add class name based on the Angular 2 ngFor loop index. using ngFor creating multiple button, when i click button add class in the specific button. like tag select For your reference Link
<button color="light" *ngFor="let category of categories" [class.tagactive]='stateOfButton' (click)="changeState(i)" let i = index;>{{category}} <span (click)="delete(i)">X</span></button>
stateOfButton: boolean = false;
categories = ['Windstorm', 'Bombasto', 'Magneta', 'Tornado', 'mango'];
changeState(index) {
this.stateOfButton = !this.stateOfButton;
}
delete(index) {
this.categories.splice(index, 1);
}
.tagactive { background: #cc3333; color:#fff;}
let i = index;
should be inside*ngFor
. – martin