AngularJS | ng-bind-template Directive

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                            

chevron_right


Output:
Before Input the Number:
ngbindtemplate
After Input the Number:
ngbindtemplate




My Personal Notes arrow_drop_up

Recommended Posts: