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 an expression in general term of programming say JavaScript. The expression is something that we write to perform or achieve something. We can understand this in a way like 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 “expression is something (a valid unit of code) that resolved to a value”. Now the agenda is what is the expression in AngularJs world. Well, unlikely in JavaScript Expression contains a similar logic. In AngularJs expressions are used to bind data to the 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 themselves hold some values.

Types of AngularJS Expressions

In AngularJs, expressions are classified as the following types.

 

                1. Number Expressions

                

                2. String Expressions

                

                3. Object Expressions

                

                4. Array Expressions

 

Before moving in detail about angularjs expressions, we will see the limitations of angular JS expressions.

       

  • 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 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.

 

To know more about number expressions in angularjs, check this AngularJS Number Expressions.

String Expressions in AngularJs

The string expression is used to perform operations on string values.

 

To know more about string expressions in angularjs, check this AngularJS String Expressions.

Object Expressions in AngularJs

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

 

To know more about object expressions in angularjs, check this AngularJS Object Expressions.

Array Expressions in AngularJs

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

 

To know more about array expressions in angularjs, check this AngularJS Array Expressions.