Angular 角度6-文本区域(变化)永远不会';t更改文本区域的内容
我有一个带有textarea的isse,如果我修改textarea上的内容,并且(更改)是触发器,它将不会通过代码更改textarea的内容 以下是一个例子: app.component.htmlAngular 角度6-文本区域(变化)永远不会';t更改文本区域的内容,angular,typescript,angular6,Angular,Typescript,Angular6,我有一个带有textarea的isse,如果我修改textarea上的内容,并且(更改)是触发器,它将不会通过代码更改textarea的内容 以下是一个例子: app.component.html <textarea #content (change)="dosomething(content.value)">{{ thecontents | json }}</textarea> 由于某些原因,当触发(更改)时,文本区域没有被更改 为什么??如何修复此问题?使用[val
<textarea #content (change)="dosomething(content.value)">{{ thecontents | json }}</textarea>
由于某些原因,当触发(更改)
时,文本区域没有被更改
为什么??如何修复此问题?使用
[value]
或[ngModel]
绑定文本区域的内容:
<textarea (change)="dosomething($event.target.value)" [value]="thecontents | json"></textarea>
<textarea (change)="dosomething($event.target.value)" [ngModel]="thecontents | json"></textarea>
有关演示,请参阅。如果不想使用ngModel,可以使用View Child指令获得相同的结果
@ViewChild('content') con:ElementRef;
thecontents={something:''};
name='';
dosomething(data) {
// this will overwrite whatever is already in the textarea
this.con.nativeElement.value=1;
}
我已编辑了您的代码,请检查此项尝试(键控)而不是(更改)。
@ViewChild('content') con:ElementRef;
thecontents={something:''};
name='';
dosomething(data) {
// this will overwrite whatever is already in the textarea
this.con.nativeElement.value=1;
}