Skip to content

Instantly share code, notes, and snippets.

@MagnusThor
Created December 10, 2015 08:55
Show Gist options
  • Select an option

  • Save MagnusThor/01c2323f0e240818cfb1 to your computer and use it in GitHub Desktop.

Select an option

Save MagnusThor/01c2323f0e240818cfb1 to your computer and use it in GitHub Desktop.
symSug
angular.module("auctionApp").directive("symSuggestions", function ($compile) {
return {
restrict: 'E',
scope: {
options: '=options',
select: '&onSelect',
trigger: '=trigger',
// transclude: true
},
link: function link(scope, element, attrs) {
var keys = { up: 38, down: 40, enter: 13 }; // key map
var index = -1;
var el = angular.element(document.querySelector("#" + attrs.trigger));
el.on("keyup", function (evt) {
switch (evt.keyCode) {
case keys.up:
index--;
break;
case keys.down:
index++;
break;
case keys.enter:
scope.select({ item: scope.options[index] });
break;
default:
};
});
},
templateUrl: "/app/suggestions.html"
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment