Tutorials References Exercises Bootcamps Videos Menu
Sign Up Create Website Get Certified Upgrade

AngularJS ng-bind-html Directive


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

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.9/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-sanitize.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.