[英]Get value of field in view with formBuilder angular2
I have this field :我有这个领域:
<form (ngSubmit)="postComment()" [formGroup]="commentForm">
<textarea formControlName="comment"></textarea>
...
I want show value in div :我想在 div 中显示值:
<div>{{commentForm.controls.comment.???}}</div>
要获得控制的价值,首先我们必须使用get方法获得控制权,然后必须获取value属性,如下所示:
<div>{{ commentForm.get('comment').value }}</div>
Now I use for Angular 12:现在我用于 Angular 12:
<div>{{ commentForm.controls['comment'].value }}</div>
or或者
<div>{{ commentForm.get('comment')?.value }}</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.