Noob web developer here.
I want to know why this fiddle doesn't work. When you click on a link in the dropdown menu, I would expect an alert to appear, but none does. The button labeled 'yell' gives the desired behavior, but it's not a dropdown element.
Javascript
function apiCtrl($scope) {
$scope.fish = [
'blum',
'blum',
'shub'
];
$scope.yell = function() {
alert("HEY");
};
}
HTML
<div ng-controller="apiCtrl">
<button ng-click='yell()'>yell</button>
<br>
<input class='autocompleted' type='text'/>
<ul>
<li ng-repeat='f in fish' tabIndex='-1'>
<a ng-click="$parent.yell()"> {{f}}
</a>
</li>
</ul>
</div>
CSS
input.autocompleted + ul {
display: none;
}
input.autocompleted:focus + ul {
padding: 2px;
margin: 1px;
list-style-type: none;
display: block;
position: absolute;
z-index: 2;
background-color: #FFF;
border: 1px solid #000;
}
I've looked for several solutions, and while there are quite a few, none of them have the added conundrum of inexperienced css mixed in. StackOverflow won't allow me more than two links in one post, so here's one of the solutions I looked at.
As you can see, I've used $parent to dodge the ngRepeat directive's transclusion.
I tried using $rootScope
to create global access to yell()
, as another solution suggested. No dice.
Removing the CSS makes it work, but what is it in there that breaks Angular?