In this tutorial, I am going to explain you about ng-bind-html directive in Angular Js. In the previous session, we have discussed ng-bind directive in Angular Js.


The ng-bind-html directive in angular js is used to bind the content to HTML element in a secure way. When we allow the HTML to our application. We need to make sure the HTML for the dangerous code. To prevent the HTML from dangerous code to we need to include the angular-sanitize.js library in our application. We can do by running our code through ngSanitize function.


You can find the angular-sanitize.js library at this location:

Here is the Syntax for declaring ng-bind-html:
<element ng-bind-html=”expression”></element> Where

Expression: Specifies a variable, or an expression to evaluate.

An example of ng-bind-html in Angular Js:

<!DOCTYPE html>
<title>ng-bind-html example</title>
<script src=""></script>
<script src=""></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 = "Welcome to: <h1>Debug On Web</h1>";

<p><b>Note:</b> In this example i includes the "angular-sanitize.js",
which has functions for removing potentially dangerous tokens from the HTML.</p>



You can find the demo of this example from here

Hope you understand this tutorial about how to prevent HTML from dangerous code.

You must read my previous article:

Thank You,

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, bool given in C:\inetpub\vhosts\\httpdocs\wp-includes\wp-db.php on line 3353