0

I have text like below which comes from JSON

<div><div>All are lucky and contect is like

I want this to be displayed properly when rendered. How do i do this.

<p>{{bodydata}}</p>
2
  • what are you getting from above snippet ?"
    – Vineet
    Commented Sep 14, 2015 at 6:38
  • ng-bind-html is what u need i think
    – Kalhan
    Commented Sep 14, 2015 at 6:39

1 Answer 1

1

you can use $sce (Strict Contextual Escaping) for displaying HTML encoded characters

function myCtrl($scope,$sce){
    $scope.html = $sce.trustAsHtml('&lt;div&gt;&lt;div&gt;All are lucky and contect is like');
}
<!DOCTYPE html>
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    </head>
  <body>
    
<div ng-controller="myCtrl">
    <span ng-bind-html="html"></span>
</div>
  </body>
  </html>

Hope it works for you :)

1
  • Everything gets displayed as html content. Say i have bold tag, Content should come as bold.
    – Hacker
    Commented Sep 14, 2015 at 7:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.