Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-bind-html Directive

AngularJS ng-bind-html Instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS Examples

Bind

the innerHTML of to the variable myText:

<

div

ng-app

=

"

myApp

"

ng-controller

=

"

myCtrl

"

​

<

p

ng-bind-html

=

"

myText

"

p

​

div

​

<

script

var app = angular.module("myApp", ['ngSanitize']); app.controller("myCtrl", function($scope) { $scope.myText = "My name is:

<

h1

John Doe

h1

"; });

script

Try it »


Definition and Usage

ng-bind-html The directive is a secure way to bind content to HTML elements.

When you want AngularJS to write HTML in your application, you need to check for dangerous code. By including the "angular-sanitize.js" module in your application, use the ngSanitize function to check the security of the code.


Syntax

<

element

ng-bind-html=

"expression"

<

/element

All HTML elements support this directive.


Parameter value

Value Description
expression Specifies the variable or expression to execute.

AngularJS Reference Manual AngularJS Reference Manual