AngularJS Expressions
In AngularJS, expressions are used to bind application data to HTML. AngularJS resolves the expression, and return the result exactly where the expression is written.
Expressions are written inside double braces {{expression}}.They can also be written inside a directive:
AnularJS expressions are very similar to JavaScript expressions. They can contain literals, operators, and variables. For example:
AngularJS Expressions Example
Note: If you remove the directive "ng-app", HTML will display the expression without solving it.
See this example:
You can also write expressions wherever you want, AngularJS will resolve the expression and return the result.
Let's take an example to change the color of input box by changing its value.
See this example:
AngularJS Numbers
AngularJS numbers are similar to JavaScript numbers.
We can use the same example by using ng-bind:
See this example:
AngularJS Strings
Same example with ng-bind:
AngularJS Objects
Same example with ng-bind:
AngularJS Arrays
Same example with ng-bind:
Difference between AngularJS Expressions and JavaScript expressions:
- AngularJS expressions can be written inside HTML, while JavaScript expressions cannot.
- AngularJS expressions support filters, while JavaScript expressions do not.
- AngularJS expressions do not support conditionals, loops, and exceptions, while JavaScript expressions do.
Similarity between AngularJS Expressions and JavaScript expressions:
- AngularJS expressions and JavaScript expressions both can contain literals, operators and variables.