Skip to content
Related Articles

Related Articles

AngularJS | ng-bind-template Directive
  • Last Updated : 29 Mar, 2019

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:

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

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




<!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:
Before selecting the radio button:
ngbindtemplate
After selecting the radio button:
ngbindtemplate

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




<!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>
    <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:
Before Input the Number:
ngbindtemplate
After Input the Number:
ngbindtemplate




My Personal Notes arrow_drop_up
Recommended Articles
Page :