What is AngularJS Expressions

Using Expressions, AngularJS binds data to HTML at the location wherever expression is mentioned on web page. It can be written inside double braces {{expression}}. It can also be written in different way like ng-bind=”expression”. ng-bind maps innerHTML to the value of expression.

Let’s take an example of a HTML paragraph with expression which are equivalent:

{{ 5+5 }}

OR

As already mentioned, AngularJS resolves expression and return the result exactly where expression is written. They can contain literals, operators and variables.




Example # 1

Output:

Sum of 10 and 20 is 30

Mentioning ng-app is important otherwise expression will not be calculated and output will be printed as

Sum of 10 and 20 is {{ 10 + 20 }}




Example # 2

Output:

Dear Satyendra Mishra,

Mature amount of your deposit amount 100 on simple rate of interest 8% for 2 years will be 16.

AngularJS Objects




Example # 3

You can also create objects called as AngularJS Objects

Output:

Dear Satyendra Mishra,

Mature amount of your deposit amount 100 on simple rate of interest 8% for 2 years will be 16.

AngularJS Arrays

Example # 4

AngularJS Arrays are initializes using ng-init in the format provided in below example. There is also a magic on select control, if you change selected item last statement of this example changes.

Output:

Additional Notes

  • AngularJS expressions do not support conditionals, loops, and exceptions, while JavaScript expressions do.
  • AngularJS expressions support filters, while JavaScript expressions do not.

 




Be Connected…

Satyendra

About Satyendra Mishra

Satyendra is a Technical Project Manager with 12+ years of experience on Project Management, Microsoft Technologies including ASP.NET, ASP.NET MVC, C#, SharePoint (On premises & Office 365), JavaScript Framework (AngularJS) and related technologies. He is a person with belief, sky is limit for a hard working and dedicated individual. That’s why he devoted himself to field of Software Development and now both are growing with each other. Every year for him turned out to be best year and he received enormous support and love from his companies and his clients from around the world. Now with vast knowledge of software development and its outsourcing process, he decided to move himself into knowledge sharing. Keep a fact in your mind about the comfort level of your clients and this will make you king/queen of your area.
View all posts by Satyendra Mishra →