angular-ui 全局键绑定 [英] angular-ui global key bindings
本文介绍了angular-ui 全局键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开始使用 angular-ui keypress 模块,想知道是否有办法让全局快捷键无论我放在身体的哪个位置都可以使用.
I've started using the angular-ui keypress module and was wondering if there is a way to make global shortcut keys which work no matter where I'm placed within the body.
我尝试将我的 ui-keydown 链接到正文,但由于它不在焦点上,因此不会触发关键事件.
I've tried linking my ui-keydown to the body but as it's not in focus the key events are not fired.
例如:
<body ui-keydown="{'pageup':'nav_to($event, \'users\')'}">
我知道我可以只关注一个 div 并将键绑定附加到它,但是当我有一个表单并且我想访问每个字段中的所有全局键绑定时会发生什么?
I know I could just focus a div and attach the key bindings to that but what happens when I have a form and I want to access all the global key bindings within each field?
推荐答案
在你的主应用控制器中试试这个:
Try this in your main app controller:
angular.element($window).on('keydown', function(e) {
console.log(e);
});
这篇关于angular-ui 全局键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文