I am trying to learn reactive forms in Angular.
I am able to write to all properties BUT numb, alts, letter and text.
**COMPONENT.TS**
createForm() {
this.userForm = this.fb.group({
fname: ['', [Validators.required]],
lname: ['', [Validators.required]],
email: ['', [Validators.email, Validators.required]],
facility: ['', [Validators.required]],
position: [''],
test: this.fb.group({
name: [''],
id: [''],
date: [''],
scored: [''],
wrong: [''],
duration: [''],
answers: this.fb.array ([
this.fb.group({
numb: [''],
alts: this.fb.group({
letter: this.fb.array([]),
text: this.fb.array([])
})
})
])
})
})
}
get answerArray() {
return this.userForm.get("answers") as FormArray;
}
**COMPONENT.HTML**
<form [formGroup]="userForm">
<div formGroupName="test">
<div formArrayName="answers">
<div *ngFor="let ans of answerArray.controls; let i = index">
<div [formGroupName]="i">
<input type="text" formControlName="">
</div>
</div>
</div>
</div>
</form>
<pre>{{ userForm.value | json}}</pre>
I get this error: core.js:6241 ERROR TypeError: Cannot read property 'controls' of null
Please if anyone can help me.
I found this example but I was not able to understand
https://stackblitz.com/edit/angular-nested-reactive-form-eg-na1ctu?file=src%2Fapp%2Fapp.component.html
question from:
https://stackoverflow.com/questions/65602843/how-can-i-access-a-properties-of-complex-nested-formgroup 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…