Dynamic variable name ng-repeat

I am implementing ng-repeat to create elements for the boot accordion interface.

I have an ng-repeat job, but the problem is that I need to dynamically create an identifier to individually customize the accordion element.

Links to my ng-repeat HTML links:

<div class="panel-heading" data-toggle="collapse" data-parent="#products-accordion" href="#collapseOne">

And the bottom links:

<div id="collapseOne" class="panel-collapse collapse in">

For this to work correctly, collapseOne must be dynamic - collapse1, collapse2, etc. How can iterate values ​​in ng-repeat? "collapse" + I am basically what I am trying to achieve.

Secondly, only the first element in the ng-repeat list requires the class "in" on this line:

<div id="collapseOne" class="panel-collapse collapse in">

This ensures the opening of the first element.

Thank you in advance for your help.

+4
source share
1

ng-repeat $index. ( : https://docs.angularjs.org/api/ng/directive/ngRepeat)

, :

<div id="collapse_{{ $index }}" class="panel-collapse collapse in">

:

<div id="collapse_0" class="panel-collapse collapse in">
<div id="collapse_1" class="panel-collapse collapse in">

Etcetera.

div , ng-class :

<div id="collapse_{{ $index }}" ng-class="{ in : $index == 0 }" class="panel-collapse collapse">
+2

All Articles