AngularJS mouse event is triggered repetitively within a loop

My goal is to activate the function setHighlight when a li element is hovered over with a mouse. The ng-mouseover event is employed within an ng-repeat loop.

The problem arises when hovering over a li element: the ng-mouseover event gets triggered multiple times, equivalent to the number of iterations. Below is a snippet of my code:

<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>

Could it be that I have placed the hover event in the wrong location?

Answer №1

When you hover over an element or any of its children, the mouseover event is triggered. So, hovering over the h4 inside the li will trigger another mouseover event. It would be more appropriate to utilize the mouseenter event instead.

ng-mouseenter="setHighlight(review.id)"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

apply a course to the designated element

Alright, I have this piece of code that deals with session and page requests. // Let's start our session session_start(); // Now let's check if there is a page request if (isset($_GET['page'])) { // If there is a requested page, we ...

Tips for saving HTML code within a concealed field utilizing jQuery

What is the best way to store a string with HTML tags in a hidden field using jQuery? I am attempting to use this code, but it's not functioning as expected: var terms = $('#TermsAndCondition').val(); alert($('#hdnTerms').val( ...

You must use the 'new' keyword in order to invoke the class constructor

Although similar questions have been asked before, my situation differs from the typical scenarios. I have a basic base class named CObject structured as follows: export class CObject extends BaseObject { constructor() { super(); } sta ...

Is there a way to detect when the escape key is pressed?

Is there a way to detect when the escape key is pressed in Internet Explorer, Firefox, and Chrome? I have code that works in IE and alerts 27, but in Firefox it alerts 0 $('body').keypress(function(e){ alert(e.which); if(e.which == 27){ ...

I'm looking to create an array of tags that contain various intersecting values within objectArray

Initially const array = [ { group: '1', tag: ['sins'] }, { group: '1', tag: ['sun'] }, { group: '2', tag: ['red'] }, { group: '2', tag: ['blue'] }, { grou ...

Encountering a "Window is undefined" error while trying to load a node_module package within a

I am attempting to incorporate the pickr package (a color picker library) into my nuxt.js application. However, I am encountering an error during import, specifically "window is undefined". Below is the code snippet: <script> import Pickr from &apo ...

What is the reason that select is unable to show the values that have been chosen

I'm struggling to understand why the code below isn't showing the selected value. Any assistance would be greatly appreciated. <select ui-select2 ng-model="associations" style="width:200px" multiple ng-options="whse.WarehouseName for whse ...

Are there any more efficient methods to retrieve an object from an arrow function in TypeScript?

Trying to retrieve an object from an arrow function is posing a challenge for me, especially with the following function f: myMethod(f: data => { return { someField: data.something }; }); I am aware that for simple types, you can condense the arrow ...

Optimizing CSS usage within Django: top recommendations

Throughout a 6-month-long project, I have continuously added new URLs. However, I am now encountering an issue when using the extend 'base.html' function on other pages where the CSS overlaps and creates confusion. My question is: What are the b ...

Having trouble with the functionality of expanding rows in Kendo grid

I am facing an issue with my Kendo grid that is populated from a SQL database. The expand feature works perfectly and displays a different Kendo grid in the expanded row when the program is first launched. However, if I perform a new search and get differe ...

My angular submit function seems to be malfunctioning as it does not add any data or show any

Currently, I am exploring Angular and attempting to utilize the POST method for my REST API calls. Below is the function found in my typeCtrl.js file: $scope.submit = function() { alert("add new type [" + $scope.newtype + "]" ); $http.post("http: ...

What is the process for triggering a sorted output from my MongoDB database by simply clicking a button?

I'm struggling with sorting my collection by rating in my code. I have this snippet where I'm sending my collection to index.ejs: router.get('/', (req, res) =>{ FILM .find().limit(6) .then(films => res.render(& ...

The functionality of React setState seems to be malfunctioning when activated

Having encountered an unusual issue with react's setState() method. Currently, I am utilizing Azure DevOps extensions components and have a panel with an onClick event that is intended to change the state of IsUserAddedOrUpdated and trigger the addOr ...

Currently exploring AngularJS and looking to create a categorized list

Currently delving into the world of AngularJS, I am embarking on creating a web application. One of my current tasks involves creating a grouped list. I am utilizing a JSON file that contains various entries like: {"title":"videoTitle", "chapter":"2", "s ...

Display the information in the second dropdown menu once the selection has been made in the first dropdown menu

I've successfully implemented a feature where selecting an option from the first drop-down list populates the second drop-down list accordingly. The HTML code snippet is as follows: <select size="1" id="BodyPart" title="" name="BodyPart"> ...

What are some tips for keeping the bootstrap datepicker constantly visible?

Description I have successfully implemented the use of an 'input type=date' as a datepicker within bootstrap 5.3, allowing users to select dates for data viewing. However, the issue I am facing is that the datepicker is only visible upon clicki ...

Dynamic conversion of values between the view and scope

I am looking to automatically translate the language of each menu title based on the user's session within their profile. To accomplish this, I plan to leverage our API Library within our php framework. In traditional php usage, we typically translat ...

Unable to exchange values on the front-end of the next.js app despite the successful operation of the swap function on the back-end

I've built a currency conversion app using next.js and it's running smoothly. However, I'm trying to implement a feature that allows users to easily swap between the From and To currencies. Here is the function code for swapping currencies: ...

The update function in model.findByIdAndUpdate() is failing to make changes

I am struggling to update a user model with new data using findByIdAndUpdate(). Despite my efforts, the model does not reflect the changes made. Below is the code snippet where I am attempting to use findByIdAndUpdate() to add an object: const User = ...

Angular: Filter causing infinite digest loop issue

I am currently working on developing a unique Angular filter that has the capability to randomly capitalize letters in the input provided. Below is the implementation: angular.module('textFilters', []).filter('goBananas', function() { ...