Angular js Expressions

M2-R5.1 · Chapter 6: JavaScript and Angular JS · 1 min read

Angular js Expressions

  • AngularJS expressions are code snippets placed inside double curly braces {{ }}.

  • Purpose: Bind data from the model ($scope) to the view (HTML).

  • Examples:

    • {{ 5 + 5 }} → outputs 10.

    • {{ student.name }} → displays the value of student.name.

  • Characteristics:

  • Similar to JavaScript expressions but evaluated by AngularJS.

  • Cannot contain control flow statements (like if or for).

  • Automatically updated when data changes.

Example - 

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="">
  <p>My first expression: {{ 5 + 5 }}</p>
</div>

<div>
  <p>My first expression: {{ 5 + 5 }}</p>
</div>

</body>
</html>

Note - Expression only runs where angular app initilizes for example in above code in first div it evalute 5 +5 = 10 bt in second div it not evalutes just markup the content {{5+5}}