Angularjs ng keydown不';我不能在有角度的地方工作
我尝试将arrow keydown事件绑定到文档,但它在angular中不起作用。 代码: } html:Angularjs ng keydown不';我不能在有角度的地方工作,angularjs,keydown,Angularjs,Keydown,我尝试将arrow keydown事件绑定到文档,但它在angular中不起作用。 代码: } html: 下面是版本1.1.1不支持ngKeydown指令。您应该至少使用版本1.1.2来使用此指令。这可能是版本问题 您可以选择此解决方案: 或者,最好的方法是为该事件编写自己的指令: 指令: var mod = angular.module('mydirectives'); mod.directive('ngKeydown', function() { return {
下面是版本1.1.1不支持
ngKeydown
指令。您应该至少使用版本1.1.2来使用此指令。这可能是版本问题
您可以选择此解决方案:
或者,最好的方法是为该事件编写自己的指令:
指令:
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">
它与不稳定的Angularjs版本配合使用,该版本已经是候选版本。这是你的小提琴
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);
});
}
};
});
<input type="text" ng-keydown="onKeydown">