Let's say we want to prevent users from using the backspace key on an input field in this scenario.
In our template, we pass the $event like so:
<input (input)="onInput($event)">
Meanwhile, in our app.component.ts file, the function looks something like this:
onInput(e:KeyboardEvent){
if(e.keycode===8){
e.preventDefault();
}else{
console.log(e.which);
}
It's worth noting that Typescript is warning us about e.keycode and e.which being deprecated.
Update: Don't forget to include double quotes in the question for :(input)="onInput()"