How can I listen for keypress event on the whole page?

后端 未结 6 1771
耶瑟儿~
耶瑟儿~ 2020-11-28 03:35

I\'m looking for a way to bind a function to my whole page (when a user presses a key, I want it to trigger a function in my component.ts)

It was easy in AngularJS w

6条回答
  •  执念已碎
    2020-11-28 03:49

    Be aware "document:keypress" is deprecated. We should use document:keydown instead.

    Link: https://developer.mozilla.org/fr/docs/Web/API/Document/keypress_event

提交回复
热议问题