我在网上搜索了我的问题的解决方案,但找不到任何合适的答案。尽管网上有大量这个特定的问题。
在我的 typescript 文件中,我有以下三种方法:
hasErrors() {
// Checking for errors
}
saveItem() {
if (this.hasErrors())
return;
// Save item
}
sendItemToAuthority() {
if (this.hasErrors())
return;
// Send item to authority
}
不知何故,sendItemToAuthority()
内的 this.hasErrors()
不被识别为函数,但在 saveItem()
中它无需任何问题。我在 Chrome 开发者工具中收到以下错误:
this.hasErrors is not a function
我发现以下可能性对我来说也不起作用(相同的错误消息):
sendItemToAuthority() {
var self = this;
if (self.hasErrors)
return;
// Send item to authority
}
有人可以引导我找到解决方案吗?我真的不明白为什么它不起作用。
最佳答案
saveItem() it works without any problem. I get the following error in chrome developer tools
this.hasErrors
is not a function
您很可能弄错了这个
。使用箭头函数:https://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html
关于javascript - this.hasErrors 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36349258/