patch Value in a nested form control using angular2

前端 未结 8 1421
日久生厌
日久生厌 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 });
    

提交回复
热议问题