AngularJS退格键

Mat*_*ima 10 keypress angularjs angular-ui

我需要在输入中捕获用户的退格.

所以我做到了这一点:

<input type="text" ui-keypress="{8:'removeTagOnBackspace()'}" ng-model="searchStudent" />
Run Code Online (Sandbox Code Playgroud)

然后,在我的控制器里面我做了这个,只是为了检查它是否正常工作:

$scope.removeTagOnBackspace = function() {
    console.log('here');
};
Run Code Online (Sandbox Code Playgroud)

但是不打印任何东西.这有什么问题?角度是否能够捕获退格?

Mat*_*ima 35

得到它了!

<input type="text" ng-keydown="removeTagOnBackspace($event)" />
Run Code Online (Sandbox Code Playgroud)

和:

$scope.removeTagOnBackspace = function (event) {
    if (event.keyCode === 8) {
        console.log('here!');
    }
};
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,这很有趣 - ng-keypress不捕获退格键事件(但对其他键有效),但ng-keydown适用于退格键. (2认同)