Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created November 25, 2014 00:11
Show Gist options
  • Save kentcdodds/5590d8cc7b65e0ac30ae to your computer and use it in GitHub Desktop.
Save kentcdodds/5590d8cc7b65e0ac30ae to your computer and use it in GitHub Desktop.
accessible ng-click
angular.module('atac.common').directive('azAction', function azActionDirective() {
'use strict';
return {
restrict: 'A',
link: function(scope, el, attrs) {
el.attr('tabindex', 0);
el.on('click', action);
el.on('keyup', function(event) {
if (event.which === 32 || event.which === 13) {
action();
}
});
function action() {
scope.$eval(attrs.azAction);
scope.$safeApply();
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment