gpt4 book ai didi

javascript - 为什么在调用有效函数时会出现类型错误? | Angular 2

转载 作者:行者123 更新时间:2023-11-28 10:45:15 27 4
gpt4 key购买 nike

每次调用此函数时,我都会收到一条错误消息,告诉我“TypeError: co.newMethod2 不是函数”

我不明白为什么我的方法在我的类型脚本文件中有效。这是我的代码

create-sharecase.component.html

<div> 
<p> Template Description </p>
<textarea [ngModel]="textValue" (ngModelChange)="newMethod2()">
</textarea>
</div>

create-sharecase.component.ts

newMethod2(){
console.log("Text Area Method");
if (this.textValue != '') {
console.log("Text Value" + this.textValue);
}}`

对我来说,这应该是有效的代码并且应该执行!所有的帮助将不胜感激!

最佳答案

看来你编写方法的方式是错误的,这是我的建议:

this.newMethod2 = () => {
console.log("Test Area Method");
if (this.textValue != ''){
console.log("Other text");
}
};

关于javascript - 为什么在调用有效函数时会出现类型错误? | Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44631693/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com