Angularjs expressions are used to bind the data to html.The angularjs expressions are written inside {{ expression }} . It also written inside a directive like ng-bind=”expression”. AngularJS expressions are much like JavaScript expressions. They can contain literals, operators, and variables.
Eg: {{ 15 + 15 }} or {{ firstName + ” ” + lastName }}
My first expression: {{ 15 + 15 }}
The output of above code is like: My first expression: 30.
If you remove the ng-app directive, HTML will display the expression as it is, without solving it:
My first expression: {{ 15 + 15 }}
The output of above code is like: My first expression: {{ 15 + 15 }}.
AngularJS application expressions are pure javascript expressions and outputs the data where they are used.
Using object
Roll No: {{student.firstname}}
Using numbers
Total amount- Books : {{cost * numbers}} Rs
In the AngularJS expressions with numbers example we just want to show a simple addition of two number variables called number1 and number2 and displayed their total(after addition) value.
After Addition: {{number1+ number2 }}
The output of above code is like: After Addition: 40.
Using array
Marks(Math): {{marks[3]}}
Subject1 : {{marks[0] }}
Subject2 : {{marks[1] }}
Subject3 : {{marks[2] }}
The output as :
Subject1 :11
Subject2 :15
Subject3 :29
Using strings
Hello {{student.firstname + " " + student.lastname}}!
In the AngularJS expressions with string example, we are going to define 2 strings of “firstName” and “lastName” and display them using expressions accordingly.
First Name : {{firstName}}
last Name : {{lastName}}
The output of above code is like:
First Name : Pritty
last Name : Times