Html & Html5

The World's best Software Development Study Portal

AngularJS Expressions

In Angular JS Expressions,expressions are used to bind application data to HTML. Angular JS resolves the expression and return the result exactly where the expression is written. Angular JS Expressions are pure JavaScript expressions and the output data where they are used.

Expressions can be written inside double braces: {{ expression }}
Written inside a directive: ng-bind="expression"

Using Numbers:

An Expression that uses numbers and operators < -, +, *, and % etc > are number Expressions.
Let’s see an example-

<div ng-app="" ng-init="quantity=1;cost=5">
<p>Total in dollar: {{ quantity * cost }}</p>

Using Strings:

It performs operations on String values.
Let’s take an example, where we will define two Strings and print them.

<div ng-app="" ng-init="firstName='Marky';lastName='Steven'">
<p>The name is {{ firstName + " " + lastName }}</p>

Using Objects:

It holds object properties and evaluates at the view, where we use it. It is similar to JavaScript objects that consist of name-value pairs.
Let’s take an example where we will define an object.

<div ng-app="" ng-init="person={firstName:'Marky',lastName:'Steven'}">
<p>The name is {{ person.lastName }}</p>

Using Arrays:

The Array Expression refers to an array of object values.
Let’s take an example-

<div ng-app="" ng-init="points=[1,15,19,2,40]">
<p>The third result is {{ points[2] }}</p>

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