typescript 获取Event属性上的typeerror

bkhjykvo  于 2023-04-07  发布在  TypeScript
关注(0)|答案(1)|浏览(138)

我试图瞄准一个事件,但我得到错误,我所尝试的是

public gotoPage(event: Event): void {
    const gettest = (event.target as HTMLElement)?.getAttribute('href');
    if (href) {
      const testModule = "value1"
      if (ssoModule) {
        event.preventDefault();
      }
    }
  }

HTML:

<ion-card-content>
  <ion-item class="no-padding" (click)="gotoPage($event)">
    <div>
{{test}}
    </div>
  </ion-item>
</ion-card-content>

但我得到的错误是

Property 'target' does not exist on type 'Event_2'.
Property 'target' does not exist on type 'RouterEvent'.
Property 'preventDefault' does not exist on type 'Event_2'.
Property 'preventDefault' does not exist on type 'RouterEvent'.

现在我使用type as any来解决这个错误,但是我想纠正这个错误,有什么解决方案吗?

qmelpv7a

qmelpv7a1#

检查您的事件类型是否从其他地方导入?

相关问题