Consider the following markup -
<ul id="list">
<li class="list-item" tabindex="0">test 1</li>
<li class="list-item" tabindex="1">test 2</li>
<li class="list-item" tabindex="2">test 3</li>
<li class="list-item" tabindex="3">test 4</li>
<li class="list-item" tabindex="4">test 5</li>
<li class="list-item" tabindex="5">test 6</li>
<li class="list-item" tabindex="6">test 7</li>
</ul>
and this piece of jQuery code -
$(".list-item").bind({
keydown: function(e) {
var key = e.keyCode;
var target = $(e.currentTarget);
switch(key) {
case 38: // arrow up
target.prev().focus();
break;
case 40: // arrow down
target.next().focus();
break;
}
},
focusin: function(e) {
$(e.currentTarget).addClass("selected");
},
focusout: function(e) {
$(e.currentTarget).removeClass("selected");
}
});
$("li").first().focus();
How do I port this code in angular? I have this so far -
<li class="list-item" ng-repeat="item in items" tabindex="{{item.tabIndex}}">
{{item.name}}
</li>
How do I do the binding in angular?