Saturday, June 27, 2015

AngularJS Expressions using Arrays

In the previous posts we saw AngularJS expressions with string, numbers and Objects, in this post we shall see on how to use AngularJS expressions involving arrays.

AngularJS Expressions using String and Numbers


AngularJS Expressions using Objects


This comes in handy when we want to display a list of values, especially while using MVC pattern if we want to display a list/table of values we can get them in an array and use the array in ng-repeat to iterate through each element in the array.

In the following example we shall see on how to use arrays and display the content of the arrays using expressions in the view.

<html ng-app>
<head>
    <meta charset="utf-8" />
    <title>AngularJS - Basic</title>
    <script src="angular.min.js"></script>
</head>
<body>
          <div ng-init="Employees=[
                                      {id:1,Name:'Tom'},
                                      {id:2,Name:'Harry'},
                                      {id:3,Name:'Peter'}]">
                    <ul>
                       <li ng-repeat="emp in Employees">
                         {{ emp.id }} - {{ emp.Name }}<br/>
                       </li>
                   </ul>
          </div>
</body>
</html>

Output:



Search Flipkart Products:
Flipkart.com

No comments: