Skip to content

Instantly share code, notes, and snippets.

@Morgul
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save Morgul/9425235 to your computer and use it in GitHub Desktop.

Select an option

Save Morgul/9425235 to your computer and use it in GitHub Desktop.
<!-- ng-class style -->
<button class="btn btn-default" ng-keypress="{enter: doStuff, up-arrow: doStuff2}">Activate Me!</button>
<!-- dual attribtues -->
<button class="btn-default" ng-keypress="doStuff" key="up-arrow">Activate Me!</button>
@Morgul

Morgul commented Mar 8, 2014

Copy link
Copy Markdown
Author

@whitelynx Here's my thoughts on the api for a keypress directive.

@whitelynx

Copy link
Copy Markdown

My issue with the first one is that you actually can't parse that as normal JS; since you have "doStuff()" and "doStuff2()", those would both get executed as soon as the attribute is parsed. Instead, they'd have to either be strings (that we'd run through eval) or function definitions.

@Morgul

Morgul commented Mar 8, 2014

Copy link
Copy Markdown
Author

Oh, my bad. That's a typo.

See, Angular has support for this; this is exactly what they do in the ng-class directive. So, I believe $parse is what we'd be looking for... but we can check the code of ng-class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment