AngularJS退格键

时间:2014-11-07 16:29:02

标签: angularjs angular-ui keypress

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

所以我做到了这一点:

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

然后,在我的控制器里面我做了这个,只是为了检查它是否有效:

$scope.removeTagOnBackspace = function() {
    console.log('here');
};

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

1 个答案:

答案 0 :(得分:34)

知道了!

<input type="text" ng-keydown="removeTagOnBackspace($event)" />

$scope.removeTagOnBackspace = function (event) {
    if (event.keyCode === 8) {
        console.log('here!');
    }
};
相关问题