Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度6-文本区域(变化)永远不会';t更改文本区域的内容_Angular_Typescript_Angular6 - Fatal编程技术网

Angular 角度6-文本区域(变化)永远不会';t更改文本区域的内容

Angular 角度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的isse,如果我修改textarea上的内容,并且(更改)是触发器,它将不会通过代码更改textarea的内容

以下是一个例子:

app.component.html

<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;

}