Update the CSS styling in Angular when the mouse enters

I have a unique dart and event with their own ids created in separate controllers. My goal is to create a functionality where hovering over the dart highlights the corresponding event with the same id, and vice versa. The events are displayed on the image's right side with labels like shiftstart, BRK, etc. To achieve this, I've implemented code that broadcasts the id from the dart controller to the event schedule controller:

Dart controller:

 $scope.clicker = function(id)
  {
      $rootScope.$broadcast("id changed", id);
  }

Event controller:

$scope.$on("id changed", function(event, id)
    {
            for(let i = 0; i < $ctrl.adherence.events.length; i++){
                if($ctrl.adherence.events[i].id == id)
      console.log("id in on: " + $ctrl.adherence.events[i].id + " other id 
      is " + id);
        }
    });

Here is my ng-mouseenter in my html for the dart:

(

<img src="${getDartImage(event)}" ng-mouseenter="clicker(${event.id})" class="dart">
);

And my ng-mouseenter for my event schedule:

<scheduled-event

                            event="event"
                            ng-repeat="event in $ctrl.adherence.events"
                            ng-mouseenter="$ctrl.clicker1($ctrl.adherence.events[$index].id)">

                        </scheduled-event>

While I can successfully match the ids and log them, I'm unsure of how to change the CSS styling of the dart by clicking on the event and vice versa.

Answer №1

To enhance user experience, consider implementing ngMouseenter and ngMouseleave events for both the dart board and score board. Broadcast an event with relevant data such as ID. https://docs.angularjs.org/api/ng/directive/ngMouseenter https://docs.angularjs.org/api/ng/directive/ngMouseleave

$scope.onDartEnter = function(dartId){
  $rootScope.$broadcast('dartEnter',{id: dartId});
};

$scope.onScoreEnter = function(scoreId){
  $rootScope.$broadcast('scoreEnter',{id: scoreId});
};

Update CSS styling:

$scope.$on("scoreEnter", function(event, params){
    var scoreObject = findScoreById(params.id);  // implementation required
    scoreObject.customClass = 'enter';
});

Example HTML structure:

<div ng-repeat="score in scores">
  <div id="name" ng-class="score.customClass">{{score.name}}</div>
</div>

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

The loading cursor in IE7 flickers incessantly, causing the webpage to lag and become un

When I move my cursor and click in text fields, the page becomes unresponsive and shows a wait cursor. If you're curious to see this issue in action, check out this video. This problem is specific to IE7. I've attempted to identify any ajax re ...

Utilizing pseudo elements (after) in CSS with the font family in Font Awesome 6 fails to function properly

I am attempting to create the div using CSS after pseudo-element and I have included the Unicode in the content with the font family being "Font Awesome 6 Free". However, nothing is showing up and I'm not sure why. Can someone please assist me? Here i ...

Switching List Icons when Hovering over Dropdown

Newbie Inquiry: I am working on a dropdown list featuring 10 items, each with black icons aligned to the right. I want to switch these icons to white when hovering over them. Appreciate any tips you may have! Thanks in advance! ...

Utilizing Adjacent Sibling Selectors within the context of a specific enclosing class

I have a question regarding the following HTML structure: <div class="a"> <div class="b"></div> <div class="c"></div> </div> My goal is to apply a specific CSS rule only within the a class: .b + .c { margin-le ...

Implementing XSRF Protection in AngularJS: A Step-by-Step Guide

Currently, I am working on a project that involves angularJs, resources, and jersey rest api's. One of my main goals is to incorporate xsrf protection into the application. I have found an example online, however, it uses ColdFusion which is not suita ...

Angular Logout does not reset local storage items

My ng-click logout function in the view: <div class="navbar navbar-default"><div class="container"> <div id="navbar-main"> <ul class="nav navbar-nav"> <li><a href="/">Home</a></li> <li ng-show=" ...

`inline-block elements are centered when displayed in Firefox`

I have a question regarding formatting h2 and h3 elements to display as inline-block. Below is the code snippet: <div id="content" class="content-width"> <h2 class="headline"> My Headline </h2> <h3 class="subheadline"> My S ...

What is the correct way to apply background-position percentage in this situation?

This problem has got me at my wit's end. Imagine a series of divs lined up horizontally. Each one is sized as a percentage of the total width, but that total width is unknown. For instance: --------------------------------- | | | ...

The AngularJS model does not reflect changes after I make edits in the editor

Currently, I am utilizing Jhtmlarea and have created a custom directive as follows: test.directive('jhtml', function () { return { restrict: 'A', replace: false, link: function (s ...

what is the best way to align text with an image using CSS

Is there a way to display a form within an image without making it messy with additional tags and text? Below is the code that I currently have: .box { width: 650px; padding-right: 15px; /* creates gap on the right edge of the image (not con ...

Using Angular to make GET requests with JSON data in PHP

Seeking assistance with connecting Angular frontend to PHP backend. Upon calling the service, I am receiving an empty array in the console. Controller: angular.module('pageModule') .controller('pageController', ['$scope', &a ...

Adjust the size of the input field as text is being typed in

Can a text input box be automatically resized as text is entered? I've been looking online but haven't come across any solutions. ...

Any recommendations besides suggesting "g"? Let's brainstorm some other ideas for g!

Looking for some assistance with a mixin I wrote that seems to be causing a loop. Any suggestions on how to optimize the code or alternative methods to achieve the desired outcome? <div class='mh-60 pt-10'>dfgdfgsdfgsdf</div> ...

Creating two divs with equal heights in React using Material-UI at 50% each

I am currently utilizing a Material UI template within a react JS project. My goal is to create a div (or Grid in MUI) that spans 100% of its container's height, containing two nested divs (or Grids) that are each set at 50% height. If the internal c ...

dyld: Unable to locate symbol: _node_module_register

Embarking on my Angular2 learning journey with the help of this GitHub repository: https://github.com/angular/quickstart After running npm install, I attempted to launch the project in a browser using npm start. However, I encountered the following error: ...

The issue I am facing with this self-closing TITLE tag causing disruption to my webpage

I am encountering a problem with my basic webpage. <html> <head> <title/> </head> <body> <h1>hello</h1> </body> </html> When viewed in both Chrome and Firefox, the webpage ...

Tips for obtaining a binary file sent through an HTTP:POST request using angular.js

I'm currently working on a project that involves using an Angular.js based viewer with a custom server. My goal is to implement an "execute & download" button. To send the request for execution, I am using an HTTP:POST method with specific headers: ...

Separating buttons (two buttons switching on and off simultaneously) and displaying the corresponding button based on the data

My current project involves creating a registration page for specific courses. While I am able to display the information correctly, I am facing an issue with the ng-repeat function. The problem lies in all the Register buttons toggling incorrectly. Additi ...

How can you style a two-item list in Material-UI React to display the items side by side?

I have a list that contains two items: 'label' and 'value'. This is the current layout: https://i.stack.imgur.com/HufX7.png How can I rearrange the items on the right to be positioned next to the label on the left? https://i.stack.im ...

Controller Undefined Angular Form Issue

Currently, I am facing an issue with my angular form that I am passing into my controller. Upon inspecting the form in the browser, I noticed that it is coming up as undefined. I have attempted to troubleshoot by changing the form's name and adjustin ...