javascript - Why is this angular keypress event bound to $document firing twice? -


i have angular directive binds keypress events on $document , broadcasts them rootscope.

the problem fires twice every single keypress. why happening? have removed rootscope broadcast piece still seeing double events being picked up

.directive('keypressevents', function ($document, $rootscope) {     return {         restrict: 'a',         link: function () {             console.log('linking keypress listener document.');             $document.bind('keypress', function (e) {                 console.log('keypress detectected on $document. broadcasting $rootscope');                 $rootscope.$broadcast('keypress', e, string.fromcharcode(e.which));             });         }     } }) 

i use in view such:

<div class="row toppad60 leftpad70" keypress-events ng-cloak>   other stuff... </div> 

edit have attempted unbind listen still seeing events fired twice on first pageload(meaning directive should not have loaded again)


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -