这可能是 Angular 版本问题。
您可以查看此解决方案:UI Utils
或者最好的方法是为此事件编写自己的指令:
指示:
var mod = angular.module('mydirectives');
mod.directive('ngKeydown', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
// this next line will convert the string
// function name into an actual function
var functionToCall = scope.$eval(attrs.ngKeydown);
elem.on('keydown', function(e){
// on the keydown event, call my function
// and pass it the keycode of the key
// that was pressed
// ex: if ENTER was pressed, e.which == 13
functionToCall(e.which);
});
}
};
});
HTML
<input type="text" ng-keydown="onKeydown">