Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: How to get index value in ng-repeat?

Tags:

angularjs

I am new is angularjs and i am trying to get the index value in ng-repeat means i want to set md-option value as index value my code is:

<md-input-container class="md-block" flex-gt-sm>
    <label>Filterable Columns</label>
        <md-select ng-model="visualization.filterable_columns" ng-change="drawFilters()" multiple="true" ng-init="index = 1">
            <md-option ng-repeat="filterable_column in vm.filterable_columns" value="{{index++}}">
                {{filterable_column.label}
            </md-option>
        </md-select>
</md-input-container>

can anyone help me about this?

like image 652
Rahul Sharma Avatar asked Dec 15 '16 06:12

Rahul Sharma


1 Answers

Add track by $index to your ng-repeat

<md-input-container class="md-block" flex-gt-sm>
   <label>Filterable Columns</label>
   <md-select ng-model="visualization.filterable_columns" ng-change="drawFilters()" multiple="true">
      <md-option ng-repeat="filterable_column in vm.filterable_columns track by $index" ng-value="{{$index}}">
         {{filterable_column.label}}
      </md-option>
   </md-select>
</md-input-container>
like image 175
CodeGems Avatar answered Oct 06 '22 12:10

CodeGems