0

I want to count how many iterations my ng-repeat did and do something with that value on my controller.

I tried to create a scope variable and increment it on repeat but couldn't get it to work. It just prints "1" next to every dropdown ng-repeat creates.

I tried this so far;

<section class="col col-2" ng-repeat="detailField in cusDetailFields" required>
  <select data-smart-select2 id="detailField-{{detailField}}" ng-model="selectedCustomerDetail[detailField]">
    <option class="text-align-right" 
      value="">{{getFieldText(detailField)}} Seçiniz
    </option>
      <option class="text-align-right" 
       value="{{detailFieldValue.Value}}"
       ng-repeat="detailFieldValue in cusDetail = (customerDetailFilters | filter : { DetailKey : detailField })">
       {{detailFieldValue.Value}}
    </option>
  </select>
                            {{counter+1}}
</section>

How can I achieve this?

Ege Bayrak
  • 1,139
  • 3
  • 20
  • 49
  • You can just get the length of your array: `cusDetailFields.length` / `cusDetail.length`. (To get the individual index, use `{{$index}}`) Also your syntax is wrong - change {{$scope.counter+1}} to {{counter+1}} – Aleksey Solovey Jan 05 '18 at 11:54
  • I can already reach length of the arrays but I need to see how many times this particular ng-repeat worked. – Ege Bayrak Jan 05 '18 at 11:56
  • Check this out https://stackoverflow.com/questions/15316363/how-to-display-length-of-filtered-ng-repeat-data – Raghav Jan 05 '18 at 13:10

0 Answers0