Shout out to @JoshDavidMiller for a super concise response. I was trying to achieve this in an ng-repeat loop and couldn't quite crack the code on how to do it gracefully. Initially, using a boolean on the scope resulted in displaying edit controls for all items in the list instead of just the one I hovered over. I almost resorted to using angular.element
(aka JQuery) and manually adding hover handlers so that only the controls for the hovered item would show. Thankfully, I didn't go down that dark path.
<div ng-repeat="item in items" ng-mouseenter="item.showEdit = true" ng-mouseleave="item.showEdit = false">
<span class="glyphicon glyphicon-edit" ng-show="item.showEdit"></span>
Hover over me.
</div>
The solution turned out to be simple - just attach the property directly to the item
, rather than the $scope
. In some cases where I couldn't add random keys to my list items, I mapped my array to a new one where the item
became a property of a wrapper object. This way, I could add any properties to the wrapper object without cluttering the original item
keys.