我已经用一些示例代码设置了一个 Plunker:http://plnkr.co/edit/upExTHzpkwtZ45mdikFr?p=preview
简明的问题是:我正在尝试使用 AngularJS 的 ng-keyUp
指令。在文档中,我只看到它用于输入框上,尽管我想要捕获页面上任何地方的按键而不仅仅是在输入框内。就像这样:
// view
<div ng-keyup="keyPress($event)">
// The bulk of my controller's view goes in here
</div>
// inside controller
$scope.keyPress = function(e){
console.log(e);
}
请参考上面的 Plunker 示例。目前它完全不能工作,没有任何日志记录。我该如何让它正常运行?
<div ng-click="keyPress($event)">
,因为在你的页面上只需点击div即可。但也许我没有理解你的情况。 - lukpaw