AngularJS NG-KEYUP可以通过其中的关键是pressed? [英] Can AngularJS ng-Keyup pass in which key was pressed?

查看:187
本文介绍了AngularJS NG-KEYUP可以通过其中的关键是pressed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关文档角的 ngkeyup 几乎是不存在的。我有我的观点一个容器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; D​​IV CLASS =容器NG-KEYUP =键preSS($事件)&GT;&LT; / DIV&GT;

这是在文档中提到的

防爆pression到时KEYUP评估。 (Event对象可作为
  $事件,可以审问了关键code,Alt键,等等。)

Expression to evaluate upon keyup. (Event object is available as $event and can be interrogated for keyCode, altKey, etc.)

这篇关于AngularJS NG-KEYUP可以通过其中的关键是pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆