目标是用户通过单击按钮将答案推送到FormArray的答案,而* ng用于单选按钮div选择正确的答案。想要只有输入和按钮元素来推动并将答案呈现给收音机组。麻烦您正确设置formarray部分...谢谢
TS
strncpy()
HTML
questionForm: FormGroup;
answers: FormArray;
this.questionForm = this.fb.group({
answers: this.fb.array([this.createItem()]),
correct: ['', [Validators.required]]
});
createItem(): FormGroup {
return this.fb.group({
data: ['', [Validators.required]],
color: ['danger']
});
}
addAnswer() {
this.answers = this.questionForm.get('answers') as FormArray;
this.answers.push(this.createItem());
}