Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ng keydown不';我不能在有角度的地方工作_Angularjs_Keydown - Fatal编程技术网

Angularjs ng keydown不';我不能在有角度的地方工作

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 {

我尝试将arrow keydown事件绑定到文档,但它在angular中不起作用。 代码:

}

html:



下面是版本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">