admin管理员组文章数量:1023773
I am trying to trigger the function setHighlight
when a li
element is hovered by mouse. The ng-mouseover
event is set in an ng-repeat
loop.
The issue is that when I hover a li
element, the ng-mouseover
is triggered multiple time. The number of trigger times equals to the number of iteration times. Here is my code snippet:
<ul>
<li ng-repeat="review in foodReviews" ng-mouseover="setHighlight(review.id)">
<h4>{{review.name}}</h4>
<b>{{review.stars}} Stars</b>
<i> -- {{review.location}} </i><br />
<blockquote> {{review.description}} </blockquote>
<br/> written by {{review.author}}
</li>
</ul>
Did I put the hover event in a wrong place?
I am trying to trigger the function setHighlight
when a li
element is hovered by mouse. The ng-mouseover
event is set in an ng-repeat
loop.
The issue is that when I hover a li
element, the ng-mouseover
is triggered multiple time. The number of trigger times equals to the number of iteration times. Here is my code snippet:
<ul>
<li ng-repeat="review in foodReviews" ng-mouseover="setHighlight(review.id)">
<h4>{{review.name}}</h4>
<b>{{review.stars}} Stars</b>
<i> -- {{review.location}} </i><br />
<blockquote> {{review.description}} </blockquote>
<br/> written by {{review.author}}
</li>
</ul>
Did I put the hover event in a wrong place?
Share Improve this question asked Aug 7, 2014 at 15:44 G ChenG Chen 1994 silver badges13 bronze badges 2- Im not that familiar with angular but yeah its looks like the mouseover is in the loop – Doc Holiday Commented Aug 7, 2014 at 15:48
- 1 mouseover event bubbles up but mouseenter does not. – PSL Commented Aug 7, 2014 at 15:52
1 Answer
Reset to default 9The mouseover event happens any time the element or any of it's children are hovered over. Therefore, whenever you hover over the h4 inside the li, another mouseover event is triggered. You should instead use the mouseenter event.
ng-mouseenter="setHighlight(review.id)"
I am trying to trigger the function setHighlight
when a li
element is hovered by mouse. The ng-mouseover
event is set in an ng-repeat
loop.
The issue is that when I hover a li
element, the ng-mouseover
is triggered multiple time. The number of trigger times equals to the number of iteration times. Here is my code snippet:
<ul>
<li ng-repeat="review in foodReviews" ng-mouseover="setHighlight(review.id)">
<h4>{{review.name}}</h4>
<b>{{review.stars}} Stars</b>
<i> -- {{review.location}} </i><br />
<blockquote> {{review.description}} </blockquote>
<br/> written by {{review.author}}
</li>
</ul>
Did I put the hover event in a wrong place?
I am trying to trigger the function setHighlight
when a li
element is hovered by mouse. The ng-mouseover
event is set in an ng-repeat
loop.
The issue is that when I hover a li
element, the ng-mouseover
is triggered multiple time. The number of trigger times equals to the number of iteration times. Here is my code snippet:
<ul>
<li ng-repeat="review in foodReviews" ng-mouseover="setHighlight(review.id)">
<h4>{{review.name}}</h4>
<b>{{review.stars}} Stars</b>
<i> -- {{review.location}} </i><br />
<blockquote> {{review.description}} </blockquote>
<br/> written by {{review.author}}
</li>
</ul>
Did I put the hover event in a wrong place?
Share Improve this question asked Aug 7, 2014 at 15:44 G ChenG Chen 1994 silver badges13 bronze badges 2- Im not that familiar with angular but yeah its looks like the mouseover is in the loop – Doc Holiday Commented Aug 7, 2014 at 15:48
- 1 mouseover event bubbles up but mouseenter does not. – PSL Commented Aug 7, 2014 at 15:52
1 Answer
Reset to default 9The mouseover event happens any time the element or any of it's children are hovered over. Therefore, whenever you hover over the h4 inside the li, another mouseover event is triggered. You should instead use the mouseenter event.
ng-mouseenter="setHighlight(review.id)"
本文标签: javascriptAngularJS mouse event is fired multiple times in a loopStack Overflow
版权声明:本文标题:javascript - AngularJS mouse event is fired multiple times in a loop - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745541507a2155204.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论