patch Value in a nested form control using angular2

前端 未结 8 1384
日久生厌
日久生厌 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:29

    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 });
    
    0 讨论(0)
  • 2020-12-19 10:30

    nested form patchvalue you need to use Array after object like this:

    this.userform.patchvalue({
     name: 'Ajay',
     approvers: [ {id:1} ]
    })
    
    0 讨论(0)
提交回复
热议问题