AngularJS | ng-bind Directive
The ng-bind Directive in AngularJS is used to bind/replace the text content of any particular HTML element with the value that is entered in the given expression. The value of specified HTML content updates whenever the value of the expression changes in ng-bind directive.
Syntax:
<element ng-bind="expression"> Contents... </element>
Where expression is used to specify the expression to be evaluated or the variable.
Example 1: This example uses ng-bind Directive to bind the product of two number to the <span> element.
<!DOCTYPE html> <html> <head> <title>ng-checked Directive</title> <script src= </script> </head> <body ng-app="gfg" style="text-align:center"> <h1 style="color:green">GeeksforGeeks</h1> <h2>ng-bind Directive</h2> <div ng-controller="app"> num1: <input type="number" ng-model="num1" ng-change="product()" /> <br><br> num2: <input type="number" ng-model="num2" ng-change="product()" /> <br><br> <b>Product:</b> <span ng-bind="result"></span> </div> <script> var app = angular.module("gfg", []); app.controller('app', ['$scope', function ($app) { $app.num1 = 1; $app.num2 = 1; $app.product = function () { $app.result = ($app.num1 * $app.num2); } }]); </script> </body> </html> |
Output:

Example 2: This example uses ng-bind Directive to bind the innerHTML of the <span> element to the variable text.
<!DOCTYPE html> <html> <head> <title>ng-checked Directive</title> <script src= </script> </head> <body style = "text-align:center"> <h1 style = "color:green">GeeksforGeeks <h2 style = "">ng-bind directive</h2> <div ng-app="" ng-init="txt='GeeksforGeeks';col='green'"> <div> <span ng-bind="txt"></span> is the computer science portal for geeks. </div> </div> </body> </html> |
Output:

Recommended Posts:
- AngularJS | ng-cut Directive
- AngularJS | ng-app Directive
- AngularJS | ng-if Directive
- AngularJS | ng-value Directive
- AngularJS | ng-jq Directive
- AngularJS | ng-src Directive
- AngularJS | ng-csp Directive
- AngularJS | Directive
- AngularJS | ng-srcset Directive
- AngularJS | ng-readonly Directive
- AngularJS | ng-selected Directive
- AngularJS | ng-paste Directive
- AngularJS | ng-required Directive
- AngularJS | ng-blur Directive
- AngularJS | ng-non-bindable Directive
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



