AngularJS Tutorial - AngularJS Expressions








Expressions are similar to an eval function in Javascript.

AngularJS expressions have the following syntax:

{{ expression }}

The {{ }} notation is for showing a variable attached to a $scope. All expressions are executed in the context of the scope and have access to local $scope variables.

Example

The following code shows how to do simple math calculation in expressions.


<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!-- w  ww .  java 2  s  .c o  m-->
<body>
1+2={{1+2}}
<h3>{{20*5/3}}</h3>
</body>
</html>

The code above is rendered as follows:





Note

AngularJS expressions, which do not allow for any control flow functions (if/else), can accept a filter and filter chains.

An expression doesn't throw errors if it results in a TypeError or a ReferenceError.