Repeating HTML elements in AgularJs

When we want to use a set of HTML elements repeatedly in our AngularJs application there is a basic directive called "ng-repeat"

Here is a set of examples for using "ng-repeat" directive

Example 1


<!DOCTYPE html>
<html>
<script src="scripts/angular.min.js"></script>
<body>
<div data-ng-app="" data-ng-init="names=['employee1','employee2','employee3']">
  <p>Looping with ng-repeat:</p>
  <ul>
    <li data-ng-repeat="employee in names">
      {{ employee }}
    </li>
  </ul>
</div>
</body>
</html>

Example2

<!DOCTYPE html>
<html>
<script src="scripts/angular.min.js"></script>
<body>

<div ng-app="" ng-init="names=[
{name:'employee1',department:'department1'},
{name:'employee2',department:'department2'},
{name:'employee3',department:'department3'}]">

<p>Looping with objects:</p>
<ul>
  <li ng-repeat="employee in names">
  {{ employee.name + ' works in ' + employee.department }}</li>
</ul>

</div>

</body>
</html>


please add a comment if you are not clear with some thing or you have something to add.

No comments:

Post a Comment