Hello every one i'm trying to make a MCQ question from for that I'm trying to catch selected value from Radio button in AngularJS. Main problem i'm facing that i'm binding data from database and those are dynamic. So i have to use ng-repeat from loading those questions in view HTML, so i can't manually handle the "ng-model" for those options. when click the submit button i need catch the question with the answer like [{QuestionId:1:AnswerId:4}, {QuestionId:1:AnswerId:3}...] or something like that. Here I've made a JSON data for previewing the scenario. Hope it'll help all to understand my problem and may solve my problem. Thanks in advance.
View code in jsfiddle
Here is the HTML
<div ng-app="myapp">
<div ng-controller="testController">
<form>
<div ng-repeat="qus in QusWithOptions">
<td>{{qus.id}}. {{qus.Question}} </td><br />
<input type="radio" name="taskGroup{{qus.id}}" ng-model="asd" value="{{qus.OptionA_KPI}}" />{{qus.OptionA}}
<input type="radio" name="taskGroup{{qus.id}}" ng-model="asd" value="{{qus.OptionB_KPI}}" />{{qus.OptionB}}
<input type="radio" name="taskGroup{{qus.id}}" ng-model="asd" value="{{qus.OptionC_KPI}}" />{{qus.OptionC}}
<input type="radio" name="taskGroup{{qus.id}}" ng-model="asd" value="{{qus.OptionD_KPI}}" />{{qus.OptionD}}
</div>
<button ng-click="SaveAnswer(asd)">Submit</button>
</form>
</div>
This is Js file
var app = angular.module("myapp",[]);
function testController($scope){
$scope.QusWithOptions = [
{id:1, Question: "What is best social network site?", OptionA: "facebook", OptionB: "twitter", OptionC: "google+", OptionD: "others",OptionA_KPI:1,OptionB_KPI:2,OptionC_KPI:3,OptionD_KPI:4 },
{id:2, Question: "Entomology is the science that studies ?", OptionA: "Behavior of human beings", OptionB: "Insects", OptionC: "Origin of scientific terms", OptionD: "The formation of rocks", OptionA_KPI:1,OptionB_KPI:2,OptionC_KPI:3,OptionD_KPI:4 },
{id:3, Question: "Eritrea, which became the 182nd member of the UN in 1993, is in the continent of ?", OptionA: "Asia", OptionB: "Europe", OptionC: "Australia", OptionD: "Europe", OptionA_KPI:1,OptionB_KPI:2,OptionC_KPI:3,OptionD_KPI:4},
{id:4, Question: "For the Olympics and World Tournaments, the dimensions of basketball court are ?", OptionA: "26 m x 14 m", OptionB: "28 m x 15 m", OptionC: "27 m x 16 m", OptionD: "28 m x 16 m",OptionA_KPI:1,OptionB_KPI:2,OptionC_KPI:3,OptionD_KPI:4 },];
$scope.SaveAnswer = function(){
window.alert();
};
}
OptionD_KPIvalue orOptionDvalue?[{QuestionId:1:AnswerId:4},{QuestionId:1:AnswerId:3}...]?