" this.startLoginAnimatioon不是一个功能"错误

时间:2017-03-07 00:46:53

标签: typescript

我正在编写一个带有打字稿的登录系统,我遇到了一个错误,我似乎无法理解为什么会发生这种情况。所以基本上:
enter image description here
当运行时在attemptLogin()函数中调用this.startLoginAnimation()函数时,它会抛出:enter image description here 当显然这是一个函数时,我还可以补充一点,视觉工作室代码不会抱怨它。

2 个答案:

答案 0 :(得分:1)

  

this.startLoginAnimation不是函数“错误

this取决于您如何调用该函数。快速修复,使用箭头:

startLoginAnimation = () => {
}

更多

this上有很多资源。 Here is a quick video about this in TypeScript classes

答案 1 :(得分:1)

我找到了解决方案,我测试了'这个'等于什么,它指的是HTMLElement类型,感谢该网站的链接,但它似乎是一个很有前途的学习资源!

对于有类似问题的人来说,这就是我所做的: 相反,如果是form.addEventListener('submit',this.attemptLogin); 我按照以下方式做了: enter image description here

相关问题