Reputation: 155
I need to repeat through some list that is present in variable "tab.excelFields
". I have been successfully able to do that, simple ng-repeat. The code is shown below:
<tr>
<th ng-repeat="field in tab.excelFields" class="btn btn-danger" style="display:table-cell;" id="{{id}}">{{field}}</th>
</tr>
Notice {{id}} field. I need to put in unique values here...1,2,3 and so on
Question: How do I add unique id to each of these fields that I am displaying? Something like "id in [1,2,3]" in conjunction with my code. Two problems:-
How to give "id in [1,2,3]
" with "field in tab.excelFields
" in ng-repeat
? Can it take two arguments?
My fields are not restricted to any fixed number. It can be one or one thousand. How to dynamically create a counter and add to this for "id
" field?
Upvotes: 1
Views: 40
Reputation: 5905
Use $index
variable inside ngRepeat scope.
<th ng-repeat="field in tab.excelFields" class="btn btn-danger" style="display:table-cell;" id="{{$index}}">{{field}}</th>
Upvotes: 3