3

I have to get the question number in this loop.

<div ng-repeat="quizqs in Quizdata.questions">
    <li ng-click="form.goTo(Form, 1)">
        <a href ng-class="{'selected' : currentStep >= 1, 'done' : currentStep > 1}">
            <div class="stepNumber"> 1 </div>
            <span class="stepDesc text-small">Question No {{quizqs.id}} - {{Quizdata_Lenght}}</span>
        </a>
    </li>
</div>
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
Deepak Kumar
  • 221
  • 3
  • 17

2 Answers2

3

You can use {{$index}}

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<div ng-app>
  <div ng-repeat="quizqs in [12,43,354,13,653]">
    <li ng-click="form.goTo(Form, 1)">
      <a href ng-class="{'selected' : currentStep >= 1, 'done' : currentStep > 1}">
        <div class="stepNumber">
        </div> <span class="stepDesc text-small">Question No {{$index}}</span>
      </a>
    </li>
  </div>
</div>
Sankar
  • 6,908
  • 2
  • 30
  • 53
0

To get the loop number or loop id in a loop, the AngularJS has an in-built variable known as - $index

This $index can only be used with ng-repeat in either the HTML files or in the directives (like filter, ng-include, custom-directives, etc.)

Remember: $index starts from 0, so whenever you wish to start from 1, you need to increment by one.

Code below:

<div class="stepNumber">
          {{index}}
</div>
<span class="stepDesc text-small">Question No: {{$index + 1}}</span>    

DEMO

Shashank
  • 2,010
  • 2
  • 18
  • 38