If you want to enhance your code, consider placing your span into a directive. In the link function, you can dynamically add the drop-down under the image using Angular's jqLite. Alternatively, if the structure of the dropdown is fixed and only its data changes, hiding it with ng-if and populating its options through a variable could be a better approach.
<span
id="dropdown-info"
ng-init= "myVar='images/info_icon_off.png'"
ng-mouseover="myVar='images/info_icon_on.png'"
ng-mouseout="myVar='images/info_icon_off.png'"
ng-click="doSomething()">
<img class="info-icon" ng-src="{{myVar}}" alt="Information" width="10" height="10">
<select ng-if="showDropDown" ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>
</span>
Next, in your JS file:
var app = angular.module('app', []);
app.controller('TestController', ['$scope',
function($scope) {
$scope.showDropDown = false;
$scope.doSomething = function() {
$scope.showDropDown = true;
}
$scope.items = [{
id: 1,
label: 'aLabel',
subItem: { name: 'aSubItem' }
}, {
id: 2,
label: 'bLabel',
subItem: { name: 'bSubItem' }
}];
}
]);
This method works well without a directive but may not be suitable for multiple spans. If you have multiple spans, consider using a directive and applying similar logic using scope:{}
.