繁体   English   中英

我正在使用 Angluar 的 Lateset 版本,我收到此错误属性“值”在类型“EventTarget”上不存在

[英]I'm using the Lateset version of Angluar and I get this error Property 'value' does not exist on type 'EventTarget'

因此,当我将 $event 与 onkeyup 事件一起使用时,我希望输入字段的值将其传递给过滤器 Function 它不起作用

<div class="container mx-auto p-5">
  <div class="searchBar">
    <div class="field">
      <p class="control has-icons-left">
        <input #filterInput class="input" type="text" (keyup)="filterNotes($event.target.value)" placeholder="Filter">
        <span class="icon is-small is-left">
          <i class="fas fa-search"></i>
        </span>
      </p>
    </div>
  </div>
</div>

class comp.net:

filterNotes(query: string) {
    // some logic
}

在这种情况下,我认为$event.target没有输入所以 typescript 不知道它是什么类型的目标,试试下面的代码:

在 .html 文件中只传递事件:

...
<input (keyup)="filterNotes($event)">
...

在.ts文件中修改你接收事件的方法:

filterNotes(event: Event): string {
  const { value } = event.target as HTMLInputElement // forcing the type
  // the rest of yout logic goes here
}

只需添加到

"angularCompilerOptions":{
    "strictDomEventtypes":false
}

在你的 tsconfig.json 文件中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM