विश्व का सबसे बड़ा हिंदी वेब डेवलपर साइट

AngularJS ng-bind-html Directive


Bind the innerHTML of the <p> element to the variable myText:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.2/angular-sanitize.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

    <p ng-bind-html="myText"></p>


var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
    $scope.myText = "My name is: <h1>John Doe</h1>";
Try it yourself »

Definition and Usage

The ng-bind-html directive is a secure way of binding content to an HTML element.

When you are letting AngularJS write HTML in your application, you should check the HTML for dangerous code. By including the "angular-santize.js" module in your application you can do so by running the HTML code through the ngSanitize function.


<element ng-bind-html="expression"></element>

Supported by all HTML elements.

Parameter Values

Value Description
expression Specifies a variable, or an expression to evaluate.