I am stuck in a small problem where I have a bunch of questions built on html from array using ng-repeat like this where by clicking previous and next button user can navigate between questions.
<ul>
<li ng-repeat="q in questions">
<h2>{{q.Question}}</h2>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> {{q.isTrue}}
</label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> {{q.isFalse}}
</label>
</li>
</ul>
<button type="button" class="btn btn-primary" ng-click="prevQuestion()">Prev</button>
<button type="button" class="btn btn-primary" ng-click="nextQuestion()">Next</button>
<button type="submit" class="btn btn-primary"ng-click="onSubmit()">Submit</button>
Controller code is
function controller($scope, quizService) {
$scope.questions = [];
updQuestion();
function updQuestion() {
var id = 1;
quizService.getQuestions(id).success(function (data) {
$scope.questions = data;
});
$scope.nextQuestion = function () {
id++;
quizService.getQuestions(id).success(function (data) {
$scope.questions = data;
});
};
$scope.prevQuestion = function () {
id--;
quizService.getQuestions(id).success(function (data) {
$scope.questions = data;
});
}
}
}
and service code
function getQuestions(id) {
return $http.get('/api/quiz/' + id);
}
My question is how do I write on onSubmit() so that it holds all checked/selected radio options in a array like structure.
What I am looking for
If I have 5 (actually 5*2) radio buttons for 5 questions ,I want to get the selected options for each 5 questions.
Thanks all.