Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

AngularJS | ng-bind-html Directive

  • Difficulty Level : Easy
  • Last Updated : 29 Mar, 2019

The ng-bind-html Directive in AngularJS is used to bind the innerHTML of an HTML element to application data, and remove dangerous code from the HTML string. $sanitize service is must for ng-bind-html directive. It is supported by all HTML elements.


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

Example: This example illustrates the ng-bind-html Directive.

<!DOCTYPE html>
<html ng-app="myApp">
    <title>ng-bind-html Directive</title>
    <script src=
    <script src=
        .green {
            color: green;
            font-size: 20px;
<body ng-controller="geek" style="text-align:center">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h2 style="">ng-bind-html Directive</h2>
    <p ng-bind-html="text"></p>
        var myApp = angular.module("myApp", ['ngSanitize']);
        myApp.controller("geek", ["$scope", function($scope) {
            $scope.text =
            "<span class='green'> GeeksforGeeks</span> is the"
              + " computer science portal for geeks.";


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!