这里,我使用的是反应式表单数组,我无法在特定索引处将 QuestionType 值插入表单数组中。以下是数组的JSON视图:
{
"SurveyName": "",
"Questions": [
{
"QuestionName": "",
"QuestionType": "",
"AnswersList": [
{
"Answer": ""
}
]
}
]
}
这里,插入值是这样的,但是当插入像这个键一样从数组中删除时,这里是下面的方法:
selectType(ID: number,event,index) {
this.QuestionType = ID;
this.SurveyForm.value.Questions[index].QuestionType = ID;
}
在数组的任何索引处插入值是动态形式,所以请建议我解决这个问题。
答案 0 :(得分:0)
使用任何FormControl
,you can call the setValue
method来更新当前值。
如果您只是尝试在表单中设置值,并假设表单控件名称与JSON属性相同:
selectType(ID: number,event,index) {
this.QuestionType = ID;
this.SurveyForm.controls['Questions'].controls[index].controls['QuestionType'].setValue(ID);
}