InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

AngularJS

  • Hello world
  • ng-init
  • ng-model
  • Controller to increment value
  • Controller - basic clock
  • Controller - ajax
  • date filter
  • include template (url)
  • include template (inline)
  • tabs using ng-switch
  • conditional style using ng-style
  • animation with ng-class
  • ng-if vs ng-hide/ng-show

AngularJS Directives

  • ng-bind
  • ng-bind-html
  • ng-bind-template
  • ng-blur
  • ng-change
  • ng-checked
  • ng-class
  • ng-class-even and ng-class-odd
  • ng-click
  • ng-cloak
  • ng-dblclick
  • ng-disabled
  • ng-focus
  • ng-hide
  • ng-href
  • ng-if
  • ng-list
 
  • Home
  • > Tutorials
  • > Javascript
  • > AngularJS

AngularJS – display html without escaping using ng-bind-html

on Feb 24, 2016

AngularJS ng-bind-html directive can be used to insert html into an element. Here is sample usage:

<p ng-bind-html="myHTML"></p>

Few points to note:

  1. One need to include ngSanitize in module dependency
  2. Javascript angular-sanitize.js should also be included along with angular.js

Example code:

<style type="text/css">p {background-color:lightgray;}</style>
<div ng-app="myApp" ng-controller='MyCtrl'>
  Server returned<p>{{ajaxHtmlData}}</p>
  How it renders using ng-bind-html<p ng-bind-html="ajaxHtmlData"></p>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-sanitize.js"></script>
<script type="text/javascript">
var module = angular.module('myApp', ['ngSanitize']);
module.controller('MyCtrl', function($scope, $http) {
  $http.get("/api/get-hello-world-with-tags.php")
  .then(function(response) {
      $scope.ajaxHtmlData = response.data;
  });
});
</script>
refresh done
try it online

Related Links

  • AngularJS API – ngBindHtml

Suggested posts:

  1. AngularJS ng-dblclick examples
  2. AngularJS ng-bind example
  3. Mac – how to always show scroll bar
  4. AngularJS ng-class-even and ng-class-odd example
  5. node – how to find version of installed package
  6. CSS general sibling selector
  7. How to include bootstrap javascript and css in wordpress post
  8. AngularJS ng-hide – conditionally hide an element
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged AngularJS, Javascript, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress