[英]set value to form control on Init not working angular2
I have following code to add control in OnInit method. 我有以下代码在OnInit方法中添加控件。
this.form = new FormGroup({});
this.form.addControl('select', new FormControl(''));
after adding the control i am not able set the value to control; 添加控件后,我无法将值设置为control;
this.form.controls['select'].SetValue()
but its throwing exception as select as undefined 但它的抛出异常如select一样未定义
您是否使用formGroup
get
方法检查了相同formGroup
:
this.form.get('select').setValue('');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.