IamCalvinBrown.com a Blog Site

Code Examples, Consulting Advice and lots of other cool things

How to get Angular to display HTML


The important items to note here are two things. 1 is the angular-sanitize.min.js file which manages the html rendering, and the ng-bind-html attribute. It can be added to a div, span, etc, however I used it on a paragraph tag in this example.


The code that's displayed to the users

<div ng-app="myApp" ng-controller="myCtrl">

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

</div>


The code (note: should be enclosed in a <script> tag

var app = angular.module('myApp', ['ngSanitize']);

var _desc = '<b>this is</b> sample html being displayed';

 app.controller('myCtrl', ['$scope' ,function ($scope) {

                $scope.description  = _desc;

            }]);

Loading