Angular does not update UI for keyboard event

Friday, July 4, 2014

I want to update page for keyboard event. I wired the keyboard event through $window.document.onkeydown. (I know this is not good but it is supposed to work)


However, I find that the page is not updating even the model is changed! Where am I missing ?



<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
function Main ($scope, $window) {
$scope.keyCode = 0;
$window.document.onkeydown = function (event) {
$scope.keyCode = event.keyCode;
console.log($scope.keyCode); //the model is changed here
};
}
</script>
</head>
<body ng-app>
<div ng-controller="Main">
{{keyCode}}
</div>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
</body>
</html>






http://ift.tt/1mQsG6i