[英]I am trying to disable Backspace inside the input field
In this example I want to disable the backspace key on the input field.在此示例中,我想禁用输入字段上的退格键。
I am passing the $event in my template as:我将模板中的 $event 传递为:
<input (input)="onInput($event)">
while in my app.component.ts file the function is like this:而在我的 app.component.ts 文件中,function 是这样的:
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. Typescript 也在抱怨 e.keycode 和 e.which 已被弃用。
Edit: I forgot to add double quotes in the question on: (input)="onInput()"编辑:我忘了在问题中添加双引号: (input)="onInput()"
You have to change the output of input element from (input)
to (keydown)
您必须将输入元素的 output 从
(input)
更改为(keydown)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.