In general to mannage a FormArray of FormGroups that belong to a FormGroup you has a getter to get the formArray
get myFormArray()
{
return this.myForm.get('myFormArray') as FormArray
}
<form [formGroup]="myFormGroup">
<!--use formArrayNem-->
<div formArrayName="myFormArray">
<!--see that we use the "getter" before and iterate over "controls"-->
<!--see the [formGroupName]="i" IN the own loop-->
<div *ngFor="let group of myFormArray.controls;let i=index"
[formGroupName]="i">
<!--here you use formControlName to input the control, e.g.-->
<input formControlName="control">
<!--to know the value of control you can use, e.g.-->
<div *ngIf="formArray.value[i].control==2">is two</div>
<!-- or -->
<div *ngIf="formArray.at(i).value.control==2">is two</div>
<!-- or -->
<div *ngIf="formArray.at(i).get('control').value==2">is two</div>
</div>
</div>
</form>
You needn't use three variables to know is if fixedProduction, onFactor or multipleFactor. If you want to use three variables, you need use tre arrays, but you can see that is unnecesary also is unnecesary the (onSelectionChange) event.
NOTE: You're using (ngModel)' -not exist (ngModel)- if you want to say
[ngModel]` remember that if you're using FormArrays or FormControl, you should NOT use ngModel-,
NOTE2: In my answer I use some like
form=new FormGroup({
formArray:new FormArray([this.getGroup(),this.getGroup()])
})
get formArray()
{
return this.form.get('formArray') as FormArray
}
getGroup()
{
return new FormGroup({
control:new FormControl(),
fixedPrice:new FormControl(),
oneFactor:new FormControl(),
})
}
I don't know what are you using
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…