Skip to content

Instantly share code, notes, and snippets.

@Morgul
Last active August 29, 2015 13:57
Show Gist options
  • Save Morgul/9425235 to your computer and use it in GitHub Desktop.
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
Copy link
Author

Morgul commented Mar 8, 2014

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

@whitelynx
Copy link

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
Copy link
Author

Morgul commented Mar 8, 2014

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