2017-08-02 63 views
0

已更新HTMLTextAreaElement值屬性,但ngModel未更新。更新HTMLTextAreaElement值屬性沒有更新ngmodel

我注意到有角度的ng-model-options。

任何我需要在ngModel更新選項中指定?

target: HTMLTextAreaElement = null; 
appendToTarget(specialCharacters: UnicodeCharacter) { 
    this.target.value = this.target.value.concat(specialCharacters); 
} 
+1

你可以設置一個plunker? –

回答

0

也許角度不知道值的變化,試試$ apply()或者做一個角度樣式。

在角2+

target: HTMLTextAreaElement = null; 
constructor(private cdr: ChangeDetectorRef){} 
appendToTarget(specialCharacters: UnicodeCharacter) { 
    this.target.value = this.target.value.concat(specialCharacters); 
    this.cdr.markForCheck(); 
    this.cdr.detectChanges(); 
} 
+0

我正在使用angular2 – ove

+0

不工作。在我使用鍵盤在文本框中輸入字符之前,ngModel仍然沒有更新。 – ove

+0

還有另一種方法可以避免這個問題。直接在函數appendToTarget(){} –