Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS backspace keypress

I need to capture user's backspaces inside an input.

So I've done this:

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

And then, inside my controller I've done this, just to check if it's working:

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

But is not printing anything. What is wrong with this? Is angular able to capture backspaces?

like image 298
Matheus Lima Avatar asked Nov 07 '14 16:11

Matheus Lima


1 Answers

Got it!

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

And:

$scope.removeTagOnBackspace = function (event) {
    if (event.keyCode === 8) {
        console.log('here!');
    }
};
like image 103
Matheus Lima Avatar answered Sep 28 '22 00:09

Matheus Lima