Hi, I'm new to AngularJS and wondered if there was an alternate way of capturing keyup/keydown events from the document level in my controllers.
The solution I came up with works fine, but seemed like a roundabout way of doing it.
Using v1.1.2, I'm adding the ng-keyup directive to the <html> tag and re-broadcasting the event:
<html lang="en" ng-keyup="$broadcast('my:keyup', $event)">
And in my Controllers:
$scope.$on('my:keyup', function(event, keyEvent) {
console.log('keyup', keyEvent);
});
I'm using the $routeProvider and ng-view to dynamically activate the controllers. I had originally tried to call a $scope function (set up by the controllers) from the ng-keyup directive but that didn't appear to work - I suspect it's a difference with multiple scopes in play (<html> outside the Controller/ng-view scope?)...still trying to wrap my head around it all.
Would it be possible to register an event listener using the $document service directly? Curious about best practice for this case.
Thanks!