AngularJS ng-bind-htmlDirective
AngularJS Example
Bind the innerHTML inside <p> to a variablemyText:
<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 Yourself »
Definition and Usage
ng-bind-htmlThe directive is a safe 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 introducing the "angular-sanitize.js" module in your application, use the ngSanitize function to check the safety 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 be executed. |
Other Extensions
AngularJS Reference Manual