AngularJS Expressions (Numbers, String, Object, Array) with Examples

Here we will learn what are the expressions in angularjs, different types of expressions in angularjs and how to use expressions in angularjs applications.

What is Expression in AngularJS

Before proceeding with what is expressions in AngularJs, Let us put some light on what is expression in general term of programming say JavaScript. So, expression is something which we write to perform or achieve something. We can understand this in this way suppose we have two numbers 5 and 7 and someone asked us to add them, then what would we do. We will write 5 + 7 to get the value of this. So writing “5 + 7” is actually an expression that will add values and results will be 12.


So we can say that “an expression is something (a valid unit of code) that resolved to a value”. Now the agenda  is what is expression in AngularJs world. Well, unlikely in JavaScript Expression contains the similar logic. In AngularJs expressions are used to bind data to HTML template.


In AngularJs expressions are basically the valid line of code that usually written in double curly braces i.e. {{ }}. The expressions can be further classified as two types of expressions those are assign value to a variable and those who itself hold some values.

Types of AngularJS Expressions

In AngularJs expression can be classified in following types 


                1. Number Expressions


                2. String Expressions


                3. Object Expressions


                4. Array Expressions


Before moving in details of the above we will see the limitation of the angular JS expression


    - We cannot use control flow statements in AngularJs like conditional, loops and exceptions.


    - We cannot declare functions in AngularJs expressions. Even in ng-init also we cannot declare functions.


    - In AngularJs expression we cannot create regular expressions.


    - We cannot use comma (,) or void in AngularJs expressions.


Besides of these limitations if we want to perform complex JavaScript code then we will first make a controller and call it from the view.

Number Expressions in AngularJS

If any expression is using the number and the operators like , -, *, % etc. those expressions we will call it as number expressions. 

String Expressions in AngularJs

The string expression is used perform operations on string values.

Object Expressions in AngularJs

The object expressions basically used to hold object properties and evaluates at the view where they are used.

Array Expressions in AngularJs

The array expressions are used to hold an array of object values.