Skip to content

Instantly share code, notes, and snippets.

@cgarvis
Created April 4, 2013 13:34
Show Gist options
  • Save cgarvis/5310371 to your computer and use it in GitHub Desktop.
Save cgarvis/5310371 to your computer and use it in GitHub Desktop.
angular.js onEnter Directive
'use strict'
angular.module('app')
.directive 'onEnter', () ->
(scope, element, attrs) ->
element.bind "keydown keypress", (event) ->
if event.which is 13
scope.$apply () ->
scope.$eval(attrs.onEnter)
event.preventDefault()
'use strict'
describe 'Directive: onEnter', () ->
beforeEach module('app')
element = {}
it 'should call function passed', inject($rootScope, $compile) ->
scope = $rootScope.new()
element = '<input type="text" on-enter="test()"></input>'
element = $compile(element) scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment