0

I'm using a simple ng-repeat to generate a list of countries and their corresponding data. Within each list is a hidden row that can be expanded and collapsed.

I'm struggling to get this hidden row to appear at the bottom of each row from the ng-repeat.

HTML:

<tr ng-repeat="country in countries">
   <td>{{country.name}}</td>
   <td>{{country.population}}</td>
   <td>{{country.currency}}</td>
   <td>{{country.gpd}}</td>

   <tr>
        <p>Expand/collapse content</p>
   </tr>
</tr>

Output:

France     61.3     EUR    54
Germany    81.5     EUR    82
Spain      12.7     EUR    78
UK         51.3     GBR    64
Expand/collapse content

Desired Output:

France     61.3     EUR    54
Expand/collapse content

Germany    81.5     EUR    82
Expand/collapse content

Spain      12.7     EUR    78
Expand/collapse content

UK         51.3     GBR    64
Expand/collapse content
0

2 Answers 2

1

You can use ng-repeat-start and ng-repeat-end as follow:

    <tr ng-repeat-start="country in countries">
       <td>{{country.name}}</td>
       <td>{{country.population}}</td>
       <td>{{country.currency}}</td>
       <td>{{country.gpd}}</td>
    </tr>
    <tr ng-repeat-end>
       <td>Expand/collapse content</td>
    </tr>   

Working fiddle : http://jsfiddle.net/nYzjY/372/

Source: https://docs.angularjs.org/api/ng/directive/ngRepeat

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, do you have a working fiddle as this doesnt seem to work
Thanks, im using v1.1.5 of Angular, would ng-repeat-start/end work with this version?
Since it's not mentioned in the documentation of the 1.1.5 version (code.angularjs.org/1.1.5/docs/api/ng.directive:ngRepeat), I think that won't work. By the way, I recommend you to migrate to the 1.2 version since the 1.1 versions were experimentals (see docs.angularjs.org/guide/migration)
i would migrate, however ive read route and resource are separate libraries now, i'd rather use 1.1.5 to only have 1 http request
1

You are repeating a tr and then you are inserting another tr after the repetition. Since you want both the tr's to be repeated. you should nest them in to one. e-g:

<div  ng-repeat="country in countries">
    <tr>
       <td>{{country.name}}</td>
       <td>{{country.population}}</td>
       <td>{{country.currency}}</td>
       <td>{{country.gpd}}</td>

       <tr>
            <p>Expand/collapse content</p>
       </tr>
    </tr>
    </div>

DEMO

2 Comments

@default - Thanks, do you have a working fiddle as this doesnt seem to work
Thanks, im using v1.1.5 of Angular, would ng-repeat-start/end work with this version?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.