question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mouseleave/mouseout and mouseover/mouseenter called multiple times when using ngFor

See original GitHub issue

I’m submitting a … (check one with “x”)

[x ] bug report 

Current behavior

I’m using ngFor to generate “li” elements with “mouseout” and “mouseenter” events.

<li *ngFor="let star of stars; let i = index;"
	[ngClass]="star"
	(mouseout)="mouseLeaveStarEvent($event)"
	(mouseenter)="mouseOverStarEvent(i, $event)"
	(click)="toggle(i, $event)"
	attr.aria-label="{{i+1}} star">
	<div class="ms-Icon ms-Icon--star" [ngClass]="star"></div>
</li>

When I keep moving my mouse pointer inside one “li” element, the mouseout and mouseenter handlers get fired multiple times.

Plunkr: https://plnkr.co/edit/D65CFnO7YIU1ile3lxaV?p=preview

Expected behavior

If I keep moving my mouse pointer inside one “li” element, I expect that mouseenter only gets called once the first time i enter that element, and mouseout to be called once when I leave that element.

The workaround right now is to NOT use ngFor by list all “li” elements manually.

  • Angular version: 2.0.0
  • Browser: Chrome
  • Language: Typescript

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
vicbcommented, Nov 15, 2016

any chance stars array is a new array on each CD cycle ?

1reaction
skreborncommented, Nov 16, 2016

@vicb It was indeed a new array on each cycle, but changing that didn’t help.

@ejaury I think the root of the problem is that mouseleave does one thing, and mouseenter does another, and they pretty much conflict. An easy solution to your problem would be to set mouseleave up on the <ul> element, like so.

In any case, this sounds like a support request, rather than a bug, so let me redirect you to an appropriate channel, should you need any further assistance. If you still believe this to be a bug, please, let us know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular USES *ngFor for mouseenter and mouseleave ...
I want to show only one change in li when I swipe multiple times, but I want to show more than two changes...
Read more >
Angular Basics: How To Use the Angular Mouseenter Event
The mouseenter event is triggered when we hover over an element. This behavior is the same as the mouseover event. However, the mouseover...
Read more >
Moving the mouse: mouseover/out, mouseenter/leave
The mouseover event occurs when a mouse pointer comes over an element, and mouseout – when it leaves. These events are special, because...
Read more >
mouseenter angular - Code Examples & Solutions For This ...
To avoid blinking problem use following code. 2. its not mouseover and mouseout instead of that use mouseenter and mouseleave. 3.
Read more >
Element: mouseleave event - Web APIs | MDN
This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found