Changing Element Colour on Hover AngularJS

后端 未结 6 859
失恋的感觉
失恋的感觉 2021-02-07 12:50

So, I\'m just getting started with angularjs and I\'m already confused. I want to change the colour of a list element that corresponds to a hex code colour that is in an array.

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 13:30

    See Plunker Demo Here

    Use ng-style to conditionally apply CSS styles - I've chosen to name this style 'personStyle'. Next, bind the ng-mouseover event to set the personStyle background-color to the person's colour attribute. Finally, bind the ng-mouseleave event to reset the personStyle when the mouse leaves the element. The changeColor() function is not needed for this solution to work.

    
    

提交回复
热议问题