2017-06-19 66 views
1

我每次调用这个函数我收到一个错误,告诉我说:“类型错误:co.newMethod2是不是一个函数”为什么在调用有效函数时会出现类型错误? |角2

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

创建-sharecase.component.html

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

创建-sharecase.component.ts

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

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

+0

你可以添加你的@Component数据? –

+0

请添加一个[最小,完整和可验证示例](https://stackoverflow.com/help/mcve)。您可以将[Plunkr](https://plnkr.co/)用于Angular。 –

+0

组件装饰已经到位的类型的脚本文件 –

回答

0

看来你写你的方法是错误的,这里的路是我提议:

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

这不适合我! –

-1

使用ngchange事件呼叫时变化的任何artibutes或改变角度功能的功能...试试这个

**strong text** 
<div> 
    <p> Template Description </p> 
    <textarea ngModel="textValue" ngChange="newMethod2()"></textarea> 
</div> 

和角度..

function newMethod2() { 
    console.log("Test Area Method"); 
    if (this.textValue != ''){ 
     console.log("Other text"); 
    } 
}; 
相关问题