I am building simple quiz app and I want to add correct
or wrong
class to element inside ng-repeat
for CSS styling purposes.
JS:
$scope.checkAnswer = function (answer) {
if (answer == $scope.answer)
{
$scope.score++;
$scope.correctAns = true;
$scope.nextQuestion();
} else {
$scope.correctAns = false;
}
};
I was trying to use ng-class
expression with no luck:
<ul id="options">
<li ng-repeat="option in options" id="answer_{{$index}}" ng-class="{'correct' : correctAns, 'wrong' : !correctAns}">
<img data-id="{{$index}}" ng-src="{{img[$index]}}" ng-click="checkAnswer({{$index}})">
</li>
</ul>
This conditional assigns "correct" to all elements in my list. I want to add this class only to one that is really correct.