In this example I want to disable the backspace key on the input field.
I am passing the $event in my template as:
<input (input)="onInput($event)">
while in my app.component.ts file the function is like this:
onInput(e:KeyboardEvent){
if(e.keycode===8){
e.preventDefault();
}else{
console.log(e.which);
}
Also Typescript is complaining about e.keycode and e.which as being deprecated.
Edit: I forgot to add double quotes in the question on: (input)="onInput()"
You have to change the output of input element from (input)
to (keydown)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.