📌  相关文章
📜  angular 无法使用 $event 访问 input 元素的 event.target.value - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:25.205000             🧑  作者: Mango

代码示例1
/*
event.target here is an HTMLElement which is the parent of all HTML elements, 
but isn't guaranteed to have the property value. 
TypeScript detects this and throws the error. 
Cast event.target to the appropriate HTML element to ensure it is 
HTMLInputElement which does have a value property:
*/

(event.target).value

// Here's another fix that works for me:
(event.target as HTMLInputElement).value