Created
March 9, 2015 07:00
-
-
Save KamilLelonek/bc1996b2b3ddc9ecc579 to your computer and use it in GitHub Desktop.
Call $scope.$apply() from $directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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