Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hover an item to show div specific to it

I am using *ngFor to loop & show items in deals array

   <div class="card item" *ngFor="let deal of deals; let i = index">
      <div class="card-body item-body">...</div>
    </div>

what i want to achieve, is when i am hovering div card in the html, his corresponding card-body div will be shown. its a fairly easy task using jquery, but i am failing to do it, using Angular.

i search for a solution for that, but didn't succeeded to implement it.. What is the way to achieve that?

like image 269
E.Meir Avatar asked Jan 19 '26 03:01

E.Meir


1 Answers

you can try something like this

  <div class="card item" *ngFor="let deal of deals; let i = index">
      <div  (mouseenter) ="onHover(i)"  (mouseleave) ="onHover(-1)>
       <div *ngIf = "i == hoverIndex" class="card-body item-body">...</div>
      </div >
    </div>

in your .ts file

hoverIndex:number = -1;

and the method

onHover(i:number){
 this.hoverIndex = i;
}
like image 187
Asanka Avatar answered Jan 20 '26 19:01

Asanka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!