AngularJS | ng-bind-html Directive
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.
Syntax:
<element ng-bind-html="expression"> Contents... </element>
Example: This example illustrates the ng-bind-html Directive.
<!DOCTYPE html> <html ng-app="myApp"> <head> <title>ng-bind-html Directive</title> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"> </script> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-sanitize.min.js"> </script> <style> .green { color: green; font-size: 20px; } </style> </head> <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> <script> 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."; }]); </script> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- AngularJS | ng-app Directive
- AngularJS | ng-if Directive
- AngularJS | ng-value Directive
- AngularJS | ng-cut Directive
- AngularJS | ng-src Directive
- AngularJS | ng-csp Directive
- AngularJS | Directive
- AngularJS | ng-jq Directive
- AngularJS | ng-selected Directive
- AngularJS | ng-readonly Directive
- AngularJS | ng-required Directive
- AngularJS | ng-paste Directive
- AngularJS | ng-srcset Directive
- AngularJS | ng-change Directive
- AngularJS | ng-blur Directive
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



