Skip to content
Related Articles

Related Articles

AngularJS ng-bind-template Directive

View Discussion
Improve Article
Save Article
  • Last Updated : 26 Aug, 2022
View Discussion
Improve Article
Save Article

The ng-bind-template Directive in AngularJS is used to replace the content of an HTML element with the value of the given expression. It is used to bind more than one expression. It can have multiple {{ }} expressions. It is supported by all HTML elements.

Syntax: The ng-bind-template Directive can be used:

As an attribute:

<element ng-bind-template="expression">
    Contents...
</element>

As an element:

<ng-bind-template ng-bind-template="expression">
    Content...
</ng-bind-template>

Parameter value:

  • expression: This parameter specifies more than one expression will be evaluated, where each expression is surrounded with {{}}. It is of string type.

Example 1: This example uses the ng-bind-template Directive to display the binding content. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        ng-bind-template Directive
    </title>
 
    <script src=
    </script>
</head>
 
<body ng-app="app" style="text-align:center">
 
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>ng-bind-template Directive</h2>
 
    <div ng-controller="geek">
        Choose one:<br>
        <label>Linear Search
            <input type="radio"
                   name="r1"
                   ng-model="search"
                   value="Linear Search" />
        </label><br>
        <label>Binary Search
            <input type="radio"
                   name="r1"
                   ng-model="search"
                   value="Binary Search" />
        </label><br>
        <span ng-bind-template=
            "{{msg}} {{search}}"></span>
        <br>
    </div>
 
    <script>
        var app = angular.module("app", []);
        app.controller('geek', ['$scope',
        function ($scope) {
            $scope.msg =
              "The better searching algorithm is: ";
            $scope.search = ""
        }]);
    </script>
</body>
</html>


Output: 

 

Example 2: This example uses the ng-bind-template Directive to display the binding content. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>ng-bind-template Directive</title>
 
    <script src=
    </script>
</head>
 
<body ng-app="app" style="text-align:center">
 
    <h1 style="color:green">GeeksforGeeks</h1>
    <h3>ng-bind-template Directive</h3>
    <div ng-controller="geek">
        <label>Football
            <input min="0"
                   type="number"
                   ng-model="Football" />
        </label><br><br>
        Count of Footballs:
        <span ng-bind-template="{{Football}}"></span><br>
    </div>
 
    <script>
        var app = angular.module("app", []);
        app.controller('geek', ['$scope',
                                function ($scope) {
            $scope.Football = "";
        }]);
    </script>
</body>
</html>


Output:

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!