AngularJS > Repeaters

ng-repeat in AngularJS

How to repeat data from array in AngularJS?


To list data from array, we shall use ng-repeat directive.

In this example, we shall initialize the array inline with the help of ng-init directive.

<div ng-app ng-init="usernames = ['Sheo', 'Narayan', 'Dutta']">
    <ul>
        <li ng-repeat="username in usernames">{{username}}</li>
    </ul>
</div>

In the above code snippet, we have kept ng-app attribute in the div itself and there is no ng-controller directive here as the initialization of the array is happening inline to this div tag with the help of ng-init directive.

Now, the ng-repeat directive is looping through each element of the usernames array and writing its value with the help of {{ username }} expression.

Output

 Views: 3151 | Post Order: 21




Write for us