Reputation: 2776
I am building a simple quiz engine as my first project in angularjs,
My view currently shows a list of questions and multi-choice answers using an ng-repeat directive.
Any suggestions as to how I might implement a feature to show the next question after the user has selected an answer to the current question?
The ng-show directive might be helpful I guess - I could do this in jQuery no problem but I'm trying to learn the best practice for angularjs.
Code sample below:
<div class="quiz">
<div class="question" ng-repeat="question in quiz.questions">
<h3>{{ question.text }}</h3>
<div class="answers" ng-repeat="answer in question.answers">
<div class="answer"><a href="{{ answer.id }}"> {{ answer.text }} </a></div>
</div>
</div>
</div>
Upvotes: 1
Views: 375
Reputation: 37711
You can create a counter, and compare it with $index in the ng-show
directive, and when an answer is selected, you just increment the counter. You'll probably end up with something more sophisticated instead of pure incrementing, though (maybe calculating the length of the answers array, etc.).
Upvotes: 1