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 ?" Commented Sep 14, 2015 at 6:38
  • ng-bind-html is what u need i think 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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

Everything gets displayed as html content. Say i have bold tag, Content should come as bold.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.