0

I have dart image being generated in one controller which has a unique id

event.img = angular.element(`
      <div class= "your-container">
        <img src="${getDartImage(event)}" 
              ng-mouseenter="$ctrl.clicker(${event.id})" class="dart">
      </div>`);
event.img = $compile(event.img)($scope);

I also have a div being generated in another controller which also has a unique id.

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

I want to match these ids and when I do a ng-mouseeenter on one element, lets say a dart, the div border - colour with the matching id changes.

Vivz
  • 6,625
  • 2
  • 17
  • 33

1 Answers1

1

You can do this with the help of ng-class. When you enter the element, just trigger the mouseenter function and set the flag to the selected Id and check if the id entered is the same as the id set in the flag.

HTML:

 <scheduled-event

    event="event"
    ng-repeat="event in $ctrl.adherence.events"
    ng-mouseenter="$ctrl.clicker1($ctrl.adherence.events[$index].id)"
    ng-class="{'bd-col':$ctrl.selectedId==$ctrl.adherence.events[$index].id}">

</scheduled-event>

JS:

this.clicker1=function(id){
  this.selectedId=id; 
}

CSS:

.bd-col{
 border-color: #444;
}
Vivz
  • 6,625
  • 2
  • 17
  • 33
  • can I change the border colour of the dart element as well who is in another controller? – Behrouz Hedayati Dec 08 '17 at 20:03
  • Yes, but in that case, you have to use a shared variable common for both controllers or better use a service to set the value. For reference https://stackoverflow.com/questions/22584342/how-to-share-the-scope-variable-of-one-controller-with-another-in-angularjs – Vivz Dec 08 '17 at 20:05
  • can I use rootScope to share the variables? – Behrouz Hedayati Dec 08 '17 at 20:13
  • Yes, you can use any of the methods in these links https://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers – Vivz Dec 08 '17 at 20:15