Hello folks! welcome back to a new section of our tutorial on AngularJS. In this tutorial, we're going to be studying about AngularJS Expressions.
Expressions binds application data to Html. Expressions are written inside double curly braces such as {{expression}}. Expressions acts similar to ngbind directives. AngularJS expressions are pure JavaScript expression and output the data where they are used.
Numbers
<p>Expense on Books : {{cost * quantity}} Rs</p>
Strings
<p>Hello {{student.firstname + " " + student.lastname}}!</p>
Object
<p>Roll No: {{student.rollno}}</p>
Array
<p>Marks(Math): {{marks[3]}}</p>
READ: AngularJS | Directives
Example
The following example illustrates the use of all the above mentioned expressions -
Create a file testAngularJS.html.
Create a file testAngularJS.html.
<html> <head> <title>AngularJS Expressions</title> </head> <body> <h1>Sample Application</h1> <div ng-app = "" ng-init = "quantity = 1;cost = 30; student = {firstname:'Kennedy',lastname:'Nkpara',rollno:102}; marks = [80,90,75,73,60]"> <p>Hello {{student.firstname + " " + student.lastname}}!</p> <p>Expense on Books : {{cost * quantity}} USD</p> <p>Roll No: {{student.rollno}}</p> <p>Marks(Math): {{marks[3]}}</p> </div> <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> </body> </html>
Output
Open the file testAngularJS.html in any web browser of your choice to see the result -
Sample Application
Hello Kennedy Nkpara!
Expense on Books : 30 USD
Roll No: 102
Marks(Math): 73
Alright guys! This is where we are going to be rounding up for this tutorial. In our next tutorial, we are going to be studying about AngularJS Controllers.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.