Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created March 9, 2015 07:01
Show Gist options
  • Save KamilLelonek/49ff23ef310c679b9f58 to your computer and use it in GitHub Desktop.
Save KamilLelonek/49ff23ef310c679b9f58 to your computer and use it in GitHub Desktop.
Call $scope.$apply() with function from $directive
.directive 'arrowListener', ->
restrict: 'A'
scope:
moveRight: '&'
moveLeft: '&'
link: (scope, elm, attrs) ->
elm.bind 'keydown', (e) ->
$scope.$apply ->
scope.moveRight() if e.keyCode == 39
scope.moveLeft() if e.keyCode == 37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment