[英]Why do I get a Type Error when calling a valid function? | Angular 2
Every time I call this function I receive an error telling me that "TypeError: co.newMethod2 is not a function" 每次调用此函数时,我都会收到一条错误消息,告诉我“ TypeError:co.newMethod2不是函数”
I don't understand why as my method is valid in my type script file. 我不明白为什么在我的类型脚本文件中我的方法有效。 Here is my code
这是我的代码
create-sharecase.component.html create-sharecase.component.html
<div>
<p> Template Description </p>
<textarea [ngModel]="textValue" (ngModelChange)="newMethod2()">
</textarea>
</div>
create-sharecase.component.ts create-sharecase.component.ts
newMethod2(){
console.log("Text Area Method");
if (this.textValue != '') {
console.log("Text Value" + this.textValue);
}}`
To me this should be valid code and should execute! 对我来说,这应该是有效的代码,应该执行! All hep will be appreciated!
所有麻将不胜感激!
It seems the way you wrote your method is wrong, here's what I propose : 看来您编写方法的方式是错误的,这是我的建议:
this.newMethod2 = () => {
console.log("Test Area Method");
if (this.textValue != ''){
console.log("Other text");
}
};
USe ngchange event for call a function when change any artibutes or change angular function ... try this 在更改任何工件或更改角度函数时使用ngchange事件来调用函数...请尝试此操作
**strong text**
<div>
<p> Template Description </p>
<textarea ngModel="textValue" ngChange="newMethod2()"></textarea>
</div>
and angular .. 和角..
function newMethod2 () {
console.log("Test Area Method");
if (this.textValue != ''){
console.log("Other text");
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.