Pete Thorne
Pete Thorne

Reputation: 2776

How might I show/hide ng-repeat elements one at a time?

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

Answers (1)

Shomz
Shomz

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

Related Questions