I have been working on a code to dynamically generate div
elements using the *ngFor
directive. Here is what I have so far:
<div *ngFor = "let item of Items">
<p>Item : {{item}} </p>
</div>
The challenge I encountered is that when I hover over a specific div
, I want only that particular div
to be highlighted with a background color.
If I use the mouseenter
attribute on the div
tag, it highlights all the div
elements instead of just the one I hovered over.
<div (mouseenter)="hovered=true"
(mouseleave)="hovered=false"
*ngFor="let item of Items"
[style.background]="hovered? 'red' : none">
<p>Item: {{item}}</p>
</div>
Does anyone know how to achieve this?