2017-01-26 2 views
4

나는 구성 요소 안에이 있습니다Angular2 업데이트 FormGroup 중첩 값?

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': '[email protected]'}); 

그러나이 값은 중첩되어 있으므로이 경우 sintax는 무엇이겠습니까? 나는 또한 시도 :

this.signupForm.patchValue({'account.email': '[email protected]'}); 

또한 여기 검색 :

this.signupForm.patchValue({account:{email: '[email protected]'}});

또 다른 해결책은 다음과 같습니다 :이 시도

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

감사

답변

12

(<FormGroup>this.signupForm.controls['account']).controls['email'].patchValue('[email protected]');

나쁜 들여 쓰기 죄송합니다.

+0

그게 전부 야! 고마워요! 나는 왜 내가 해결책으로 깨닫지 못했는지 모르겠다 ... 지금 그것은 명백하게 보인다! – Ismaestro

+0

내 시간을 많이 절약 .. – roshini

+0

위의 솔루션에서 계정 대신 variable을 사용하는 방법. –

관련 문제