问题描述
有关文档角的
几乎是不存在的。我有我的观点一个容器div,我想申请按键事件,但我想从我的控制器功能控制它们。
The documentation for Angular's
ngkeyup
is virtually non-existant. I have a container div for my view that I want to apply key events to, but I want to control them from a function in my controller.
我试图做这样的事情:
查看:
<div class="container" ng-keyup="keyPress(e)"></div>
控制器:
$scope.keyPress = function(e){
console.log(e); // where 'e' is the keycode of whatever was pressed
}
这是可能的呢?我找不到任何信息,任何地点,在什么 NG-KEYUP
实际上并和如何使用它!举例来说,我想触发一个事件时,左箭头键(37)
是pressed,我怎么会用角实现这一目标?
Is this possible at all? I can't find any information, anywhere, on what ng-keyup
actually does and how to use it! For instance, I want to trigger an event when the left arrow key (37)
is pressed, how would I achieve this with Angular?
推荐答案
您可以做这样的事情,通过 $事件
对象。
You can do something like, passing $event
object.
&LT; DIV CLASS =容器NG-KEYUP =键preSS($事件)&GT;&LT; / DIV&GT;
这是在文档中提到的
防爆pression到时KEYUP评估。 (Event对象可作为
$事件,可以审问了关键code,Alt键,等等。)
这篇关于AngularJS NG-KEYUP可以通过其中的关键是pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!