Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AngularJS ng-repeat on <ul> tag without repeating it?

With this code:

<ul data-ng-repeat="airport in airports">
            <li>{{airport.code}}</li>
            <li>{{airport.city}}</li>
            <li>{{airport.name}}</li>
</ul>

I end up with three <ul>, each with one <li> inside of them.

How can I get one <ul> with three <li> inside?

like image 442
René Thomassen Avatar asked Sep 10 '13 19:09

René Thomassen


2 Answers

You can used ng-repaet as:

<ul>
    <li ng-repeat="rp in $ctrl.repeat">{{rp}}</li>
</ul>

{{rp}} repeat object x time

Output should like this:

.list 1

.list 2

.list 3

like image 61
Rizwan Avatar answered Oct 10 '22 14:10

Rizwan


You can use ng-repeat-start directive:

<ul>
    <li ng-repeat-start="airport in airports">{{airport.code}}</li>
    <li>{{airport.city}}</li>
    <li ng-repeat-end>{{airport.name}}</li>
</ul>

Here it is working in plnkr.

like image 28
Ufuk Hacıoğulları Avatar answered Oct 10 '22 13:10

Ufuk Hacıoğulları