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 the ng-bind directive.
Syntax:
Contents...
Parameter value:
- expression: It is used to specify the expression to be evaluated or the variable.
Example 1: This example implements the ng-bind Directive to bind the product of two numbers to the element.Â
<html>
<head>
<title>ng-bind Directivetitle>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
script>
head>
<body ng-app="gfg" style="text-align:center">
<h1 style="color:green">
GeeksforGeeks
h1>
<h3>ng-bind Directiveh3>
<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 implements the ng-bind Directive to bind the innerHTML of the element to the variable text.Â
<html>
<head>
<title>ng-bind Directivetitle>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
script>
head>
<body style="text-align:center">
<h1 style="color:green">
GeeksforGeeks
h1>
<h3>ng-bind directiveh3>
<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:
