trainingtrains Logo

91-9990449935

 0120-4256464

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

Test it Now

Note: If you remove the directive "ng-app", HTML will display the expression without solving it.

See this example:

Test it Now

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:

Test it Now

AngularJS Numbers

AngularJS numbers are similar to JavaScript numbers.

Test it Now

We can use the same example by using ng-bind:

See this example:

Test it Now

AngularJS Strings

Test it Now

Same example with ng-bind:

Test it Now

AngularJS Objects

Test it Now

Same example with ng-bind:

Test it Now

AngularJS Arrays

Test it Now

Same example with ng-bind:

Test it Now

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.