What is AngularJS way to create global keyboard shortcuts?

后端 未结 12 2124
一整个雨季
一整个雨季 2020-11-30 22:04

I suppose that I should use directive, but it seems strange to add directive to body, but listen events on document.

What is a proper way to do this?

UPDATE:

12条回答
  •  暖寄归人
    2020-11-30 23:01

    Use $document.bind:

    function FooCtrl($scope, $document) {
        ...
        $document.bind("keypress", function(event) {
            console.debug(event)
        });
        ...
    }
    

提交回复
热议问题