AngularJS - ng-repeat to assign/generate a new unique ID

后端 未结 3 491
离开以前
离开以前 2020-12-14 07:20

Im using a simple ng-repeat to generate a list of countries. Within each list is a hidden row/div that can be expanded and collapsed.

The issue that i a

相关标签:
3条回答
  • 2020-12-14 07:35

    {{$index+1}} will show 1-5 for every page of pagination in order to change serial no as per page no of pagination, use {{$index+curPage*5+1}}, where curPage is your current page in pagination.

    0 讨论(0)
  • 2020-12-14 07:39

    You can use $index https://docs.angularjs.org/api/ng/directive/ngRepeat

    <li ng-repeat="country in countries" data-show="????">
        {{country.name}} has population of {{country.population}}
    
        <div id="country-{{$index}}">
            <p>Expand/collapse content
        </div>
    </li>
    
    0 讨论(0)
  • 2020-12-14 07:50

    You may need something like below when you got a nested ng-repeat:

    <label id="country-{{$parent.$index}}-{{$index}}" ng-repeat="city in country.cites"> {{city.name}} </label>

    0 讨论(0)
提交回复
热议问题