How to define and loop Array in Angular JS

In the previous post we learn how setup angular JS and execution. Today we will learn following directives

ng-init : Is used to initialize the varibale(number, strings, arrays ..etc)

ng-model : It is used to synchronize variable with model

ng-repeat: This directive is used to iterate elements in array

The follwoing example demonstrates, how to define array and display elements in html file


<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>

<div data-ng-app="" data-ng-init="brands=['apple','motorola','becbe']">
<p>Looping with ng-repeat:</p>
<ul>
<li data-ng-repeat="x in brands">
{{ x }}
</li>
</ul>
</div>

</body>
</html>

Output:

Looping with ng-repeat:

  • apple
  • motorola
  • becbe

 

SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment