Previously, I dealt with the problem using jQuery as follows:
$("#textInput").keydown(function (e) {
return e.which !== 32;
});
How would you approach it with the new Angular and Typescript?
Previously, I dealt with the problem using jQuery as follows:
$("#textInput").keydown(function (e) {
return e.which !== 32;
});
How would you approach it with the new Angular and Typescript?
i just decalre
$
on the top of my class like thisthan you are able to use
$
in your code as you explainedOtherwise there are various methods in angular2 like
keyup
andkeydown
and so on you can use those alsoIn component you should implement this method .
}
After that,In HTML tag,
You should use event binding in your template like this:
Then in your controller define the
keyDownHandler()
function:Or simply ;
I managed to create a handy directive which accepts what ever key number you give it and prevents them
And then use it like
This will prevent space , up , left , down , right keys :D