AngularJS Expression

AngularJS, the predecessor of Angular, introduced the concept of expressions as a way to bind dynamic data to HTML templates. AngularJS Expressions are written within double curly braces {{ }} and are evaluated by the framework to generate values displayed in the UI. These expressions are based on JavaScript and can include variables, function calls, operators, and literals.

Syntax:

In the below syntax, the msg variable is defined in the AngularJS controller and its value will be displayed in the <p> element.

<p> 
{{ mymsg }}
</p>

Example: Below example demonstrates the usage of expressions in the Angular JS application.

HTML




<!DOCTYPE html>
<html ng-app="myApp">
  
<head>
    <title>
          Angular JS Expression
      </title>
    <script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
    </script>
</head>
  
<body>
    <div ng-controller="MyCtrl">
        <h1 style="color: green">
            w3wiki
        </h1>
        <h2>AngularJS Expressions </h2>
  
        <p>{{ mymsg }}</p>
    </div>
  
    <script>
        angular.module('myApp', [])
        .controller('MyCtrl', function ($scope) {
            $scope.mymsg = 'Welcome to w3wiki!';
        });
    </script>
</body>
  
</html>


Output:

Difference between AngularJS Expression and Angular Expression

AngularJS is a JavaScript-based framework that can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. Angular on the other hand is a client-side TypeScript-based, front-end web framework by Google. 

Angular is a great, reusable UI (User Interface) library for developers that help in building attractive, and steady web pages and web application.

An Expression in Angular or Angular JS is a code snippet that can be simple or complex JavaScript-like code, like, the variable references, function calls, operators, and filters, etc, written within double curly braces {{ }} in order to evaluate & display dynamic values or perform calculations in the template.

In this article, we will learn about Angular Expression & Angular JS Expression, their implementations & the difference between them.

Similar Reads

AngularJS Expression

AngularJS, the predecessor of Angular, introduced the concept of expressions as a way to bind dynamic data to HTML templates. AngularJS Expressions are written within double curly braces {{ }} and are evaluated by the framework to generate values displayed in the UI. These expressions are based on JavaScript and can include variables, function calls, operators, and literals....

Angular Expression

...

Contact Us