Angular2更新FormGroup嵌套值?

ism*_*tro 14 forms components typescript angular

我在组件内部有这个:

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,...]]
});
Run Code Online (Sandbox Code Playgroud)

我想设置电子邮件字段的值.我试过这个,但没有运气:

this.signupForm.patchValue({'email': 'myvalue@asd.com'});
Run Code Online (Sandbox Code Playgroud)

但是这个值是嵌套的,所以在这种情况下,sintax是什么?我也尝试过:

this.signupForm.patchValue({'account.email': 'myvalue@asd.com'});
Run Code Online (Sandbox Code Playgroud)

也在这里搜索:

https://angular.io/docs/ts/latest/api/forms/index/FormGroup-class.html#!#patchValue-anchor

谢谢

Kar*_*arg 33

试试这个:

this.signupForm.patchValue({account:{email: 'myvalue@asd.com'}});

另一种解决方案是

(<FormGroup>this.signupForm.controls['account']).controls['email'].patchValue('myvalue@asd.com');
Run Code Online (Sandbox Code Playgroud)

抱歉压痕不好.