我在组件内部有这个:
private formBuilder: FormBuilder ... signupForm: FormGroup; ... this.signupForm = this.formBuilder.group({ 'name': [null, Validators.required], 'account': this.formBuilder.group({ 'email': [null, [Validators.required, ...]], 'confirm_email': [null, Validators.required], }, {validator: ValidationService.emailMatcher}), 'password': [null, [Validators.required,...]] });
我想设置电子邮件字段的值.我试过这个,但没有运气:
this.signupForm.patchValue({'email': 'myvalue@asd.com'});
但是这个值是嵌套的,所以在这种情况下,sintax是什么?我也尝试过:
this.signupForm.patchValue({'account.email': 'myvalue@asd.com'});
也在这里搜索:
https://angular.io/docs/ts/latest/api/forms/index/FormGroup-class.html#!#patchValue-anchor
谢谢
试试这个:
this.signupForm.patchValue({account:{email: 'myvalue@asd.com'}});
另一种解决方案是
(this.signupForm.controls['account']).controls['email'].patchValue('myvalue@asd.com');
抱歉压痕不好.