这个问题在这里已有答案:
我需要检测按下div的按键。 In this plunk我有一个div,但是如果我先点击它然后按一个键(例如Del)那么就不会发生任何事件。如何使这项工作?
HTML
Click on the div and press a key:
<div ng-keypress="pressedKey($event)">
</div>
Key pressed: {{myKey}}
使用Javascript
angular.module("app", [])
.controller('ctl', function($scope) {
$scope.pressedKey = function(event) {
$scope.myKey = event.key;
}
});