Adit A. Pillai Adit A. Pillai - 1 year ago 110
AngularJS Question

How to parse the html which is embedded in a string inside a JavaScript object?


angular.module('module', []);

angular.module('module').controller('hello', function($scope) {
$scope.obj = {
"text": "<u>HelloWorld</u>"




<div ng-app='module' ng-controller='hello'>

<br> Expected:<u>HelloWorld</u>

I am trying to read an object stored in a JSON and then print it on my web page.

I have provided a link to the code above.

I am expecting the output to be a string "HelloWorld" which is underline.


  • I cannot edit the JSON

  • obj is the object that is being fetched, I could not share the JSON so i have used a hardcoded value.

Answer Source

You can use ng-bind-html and ng-bind-html-unsafe for that kind of purpose. you have to include ngSanitize from angular-sanitize.

<p ng-bind-html="obj.text"></p>

The example is shown here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download