In
the post AngularJS Expressions using String and Numbers, we saw on how to use
simple string and numbers in expressions,
we can also create complex objects and use them in expressions, this becomes more handy when we want to implement MVC
pattern using AngularJS, we can define model objects and use them in the View
layer to display model object properties.
The following example shows how to use Objects in Expressions
<html ng-app>
<head>
<meta charset="utf-8" />
<title>AngularJS - Basic</title>
<script src="angular.min.js"></script>
</head>
<body>
<div ng-init="Employee={name:'John',age:25,dob:'01-01-1990'}">
<p>Name :<b> {{ Employee.name }} </b></p>
<p>Age :<b> {{ Employee.age }} </b></p>
<p>DOB :<b> {{ Employee.dob }} </b></p>
</div>
</body>
</html>
Output:
The following example shows how to use Objects in Expressions
<html ng-app>
<head>
<meta charset="utf-8" />
<title>AngularJS - Basic</title>
<script src="angular.min.js"></script>
</head>
<body>
<div ng-init="Employee={name:'John',age:25,dob:'01-01-1990'}">
<p>Name :<b> {{ Employee.name }} </b></p>
<p>Age :<b> {{ Employee.age }} </b></p>
<p>DOB :<b> {{ Employee.dob }} </b></p>
</div>
</body>
</html>
Output:
No comments:
Post a Comment