Expressions in AngularJS are just like JavaScript code snippets. JavaScript code is usually written inside double braces: {{expression}}. In other words, Angular Expressions are JavaScript code snippets with limited sub-set. Expressions are included in the HTML elements.
Like JavaScript expressions, AngularJS expressions can also have various valid expressions. We can use the operators between numbers and strings, literals, objects and arrarys inside the expression {{ }}. For example,
- {{ 2 + 2 }} (numbers)
- {{Name + " " + email}} (string)
- {{ Country.Name }} (object)
- {{ fact[4] }} (array)
Example
- <div ng-controller="appController">
- <span>
- 4+5 = {{4+5}}
- </span>
- <br />
- <br />
- <span ng-init="quantity=5;cost=25">
- Total Cost = {{quantity * cost}}
- </span>
- </div>