我刚刚在Angular应用程序中遇到一个错误。所以它开始了。
在我的";app.component.html";文件,我有以下代码。
<input (keyup)="handleEvent($event.target.value)" />
在我的";app.component.ts";,我有以下代码。
export class AppComponent {
title = 'blog';
handleEvent(event: any) { // without type info
console.log(event);
console.log(event.target.value);
}
我的问题是,当我试图访问"0"中的输入值时;app.component.html";用"$event.target.value";,我得到以下错误。
**[0mProperty 'value' does not exist on type 'EventTarget'.**
另一方面,当我只通过"$事件";作为我的";handleEvent";函数,然后我就可以成功地访问我的输入值。你可以看到我的";app.component.ts";文件
为什么会发生这种事?是否存在我们无法访问的块";事件";";app.component.html";?
请忽略任何不成熟的错误。提前谢谢。
在某些上下文中使用$any((类型的强制转换函数来选择退出表达式的一部分的类型检查
<input (keyup)="handleEvent($any($event).target.value)" />
参考