I have dynamically created a table using nested ngFor loops. When I mouseover one of the spans the background colour changes for all of the spans. The behaviour I want and expect is that the background will change only on the span that I am on and not for all of them at the same time.
<div *ngFor="let col of table; let j=index">
<span *ngFor="let row of col; let i=index" (mouseover)="hover=true" (mouseleave)="hover=false" [ngStyle]="{backgroundColor: hover==true ? 'lightblue' : 'transparent'}">{{ row['r' + j + 'c' + i] }}
</span>
</div>
This is how the table object was created,
table: {}[] = [];
cols: {}[]= [];
cell: {}= null;
c:number;
r:number;
key: string = null;
rowslength:number = 2;
columnslength:number = 2;
constructor() {
this.makeTable();
}
makeTable(){
for(this.r = 0; this.r < this.rowslength; this.r++){
for(this.c = 0; this.c < this.columnslength; this.c++){
this.key = "r" + this.r + "c" + this.c;
this.cell = { [this.key]: this.key };
this.cols.push(this.cell);
}
this.table.push(this.cols);
this.cols = [];
}
}