I have a list of questions as given below.
public questionList = [
{
question:{
id: "Q1",
query:"query 1"
},
options:[
{
id: "opt1",
text: "Q1_opt1"
},
{
id: "opt2",
text: "Q1_opt2"
}
],
selected:{
id:"",
text:""
}
},
{
question:{
id: "Q2",
query:"query 2"
},
options:[
{
id: "opt1",
text: "Q2_opt1"
},
{
id: "opt2",
text: "Q2_opt2"
}
],
selected:{
id:"",
text:""
}
}
];
My intention is to list the questions along with options as radio buttons. Whenever somebody selects an option, the id of the selected option should be assigned to "selected.id" which is associated with that question.
Following is the HTML part.
<div *ngFor="let question of questionList">
{{question.question.query}}
<br>
<div *ngFor="let option of question.options">
<input type="radio" value="{{option.id}}" [(ngModel)]="question.selected.id">{{option.text}}
<br>
</div>
{{question.selected | json}}
<br>
<br>
</div>
But when i select the any option for the first question, option for the second question is also getting selected and vise versa.
what would have gone wrong here?