Angular forms - access FormArray in child component template

后端 未结 1 2015
天涯浪人
天涯浪人 2021-01-24 09:42

I have a component that takes several FormControls and FormArrays as inputs. I\'m accessing the FormControls from the child component like

1条回答
  •  盖世英雄少女心
    2021-01-24 10:35

    Update there was a type error, jsut corrected

    You can use a FormArray like a FormGroup, but be carefully with the "notation", if normally we use [formGroup]="i", now we use [formGroup]="group".

    It's only think about what is myFormArray.controls

    Prop1 Required
    Prop2 Required
    myFormArray=new FormArray([ new FormGroup({ prop1:new FormControl('',Validators.required), prop2:new FormControl('',Validators.required) }) ])

    If your formArray is a FormArray of controls use directly formControl

    Required
    myFormArray2=new FormArray([ new FormControl('',Validators.required), new FormControl('',Validators.required) ])

    See in stackblitz

    0 讨论(0)
提交回复
热议问题