patch Value in a nested form control using angular2

前端 未结 8 1410
日久生厌
日久生厌 2020-12-19 09:34

I need to set a value in a nested control in a FormBuiler and the model is the following:

this.addAccForm = this.fb.group({
      accid: [\'\', Validators.re         


        
8条回答
  •  感动是毒
    2020-12-19 10:18

    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');
    

提交回复
热议问题