Dinesh Kumar
Dinesh Kumar

Reputation: 169

Angular JS "ng-repeat" is not working

here is my code: In this code my ng-repeat is not working

    <br/>
        <h3>Looping with ng-repeat directive</h3>   
            <ul>
                <li data-ng-repeat="name in names init">{{names}}</li>

            </ul>

    </div>      
    <script src="angular.min.js"></script>
</body>
</html>

Upvotes: 0

Views: 102

Answers (2)

LST
LST

Reputation: 46

ng-repeat works like a for loop (if you're familiar with Java, it works exactly like a for-each loop). The syntax is

ng-repeat="item in listOfItems"

http://docs.angularjs.org/api/ng/directive/ngRepeat

What happens here is that the repeater will generate the content annotated with the ng-repeat for as many items the list contains (see the example here).

In your case, as Vamsi V said, you'd need something like

<li ng-repeat="name in names">{{ name }}</li>

Upvotes: 2

Vamsi
Vamsi

Reputation: 9780

If names is an array of names like

$scope.names = ['John', 'Jack', 'Joe'];

you have to use

<li ng-repeat="name in names">{{ name }}</li>

If persons is an array of objects like

$scope.persons = [{name: 'John', age: 20}, {name: 'Jack': age: 21}];

you have to use

<li ng-repeat="person in persons">{{ person.name }}</li>

Upvotes: 1

Related Questions