2017-06-19 25 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"); 
    } 
}; 
相關問題