Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created March 9, 2015 07:00
Show Gist options
  • Save KamilLelonek/bc1996b2b3ddc9ecc579 to your computer and use it in GitHub Desktop.
Save KamilLelonek/bc1996b2b3ddc9ecc579 to your computer and use it in GitHub Desktop.
Call $scope.$apply() from $directive
.directive 'arrowListener', ->
restrict: 'A'
scope:
moveRight: '&'
moveLeft: '&'
link: (scope, elm, attrs) ->
elm.bind 'keydown', (e) ->
scope.moveRight() if e.keyCode == 39
scope.moveLeft() if e.keyCode == 37
$scope.$apply()
.controller 'NumCtrl', ($scope) ->
history = []
$scope.numbersDisplayed = [0, 1, 2, 3, 4, 5]
$scope.moveRight = ->
history.unshift $scope.numbersDisplayed.shift()
$scope.moveLeft = ->
$scope.numbersDisplayed.unshift history.shift()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment