patch Value in a nested form control using angular2
Try with theese codes
this.addAccForm.patchValue({cyc: {cycid: 1234567 }});
this.addAccForm.patchValue({cyc: { det : {dcycid: 9876543}}});
Another solution is:
(< FormGroup >this.addAccForm.controls['cyc']).controls['cycid'].patchValue('1234567');
(< FormGroup >this.addAccForm.controls['cyc']).controls['det'].controls['dcycid'].patchValue('1234567');
This did the trick for me:
this.addAccForm.patchValue({'cyc': {cycid: 1234567 }});
Update
Updating nested fields of an Angular FormGroup
looks cleaner using the get
method, like this:
this.addAccForm.get('cyc.det.dcycid').patchValue(9876543);
And if for some reason you like the object syntax:
this.addAccForm.get('cyc.det').patchValue({ dcycid: 9876543 });