我需要在输入中捕获用户的退格键。
所以我做到了这一点:
<input type="text" ui-keypress="{8:'removeTagOnBackspace()'}" ng-model="searchStudent" />
然后,在我的控制器里面我做了这个,只是为了检查它是否有效:
$scope.removeTagOnBackspace = function() {
console.log('here');
};
但是不打印任何东西。 这有什么问题?角度是否能够捕获退格?
答案 0 :(得分:34)
知道了!
<input type="text" ng-keydown="removeTagOnBackspace($event)" />
和
$scope.removeTagOnBackspace = function (event) {
if (event.keyCode === 8) {
console.log('here!');
}
};