How to Use Expressions in Angularjs?

In AngularJS, expressions are used to bind application data to HTML. AngularJS resolves the expression, and returns the result where the expression is written.

In AngularJS, expressions are used to bind data from models to HTML DOM elements and similar to the ng-bind directive. Expressions also allow you to use variables, objects, operators and literals.

AngularJS expression binds application data to HTML element, we write it inside two curly braces, it reminds us of javascript expression. Its angular expression is different from javascript.

Expressions are written in double braces {{expression}}, they can also be written inside instructions.

ng-bind="expression".

Example Code

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app>
<p>My angularjs expressions: {{ 5 + 5 }}</p>
</div>
</body>
</html>

Example Result

My angularjs expressions: 10

Angular Expressions Number

We can use numbers or numerical values ​​in angular expressions and numerical values ​​can also contain decimal values

Example Code

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="" ng-init="quantity=6;cost=6">
<p>Total in dollar: {{ quantity * cost }}</p>
</div>
</body>
</html>

Example Result

Total in dollar: 36