JSFiddle - React, Tailwind, and code Playground
by Satheesh Santhosh
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<div ng-app>
<div ng-controller="TestController">
{{question.choices | json}}
<div>
<label data-ng-repeat="choice in question.choices">
<input type="radio" name="response" ng-click="setChoiceForQuestion(question.choices, choice)" value="true" ng-model="choice.isUserAnswer"/>
{{choice.text}}
</label>
</div>
</div>
</div>
JavaScript
function TestController($scope) {
$scope.setChoiceForQuestion = function (q, c) {
angular.forEach(q, function (c) {
c.isUserAnswer = false;
});
c.isUserAnswer = true;
};
$scope.question = {
questionText: "This is a test question.",
choices: [{
id: 1,
text: "Choice 1",
isUserAnswer: "false"
}, {
id: 2,
text: "Choice 2",
isUserAnswer: "true"
}, {
id: 3,
text: "Choice 3",
isUserAnswer: "false"
}]
};
}