1

I use an editor to add comment and this content save as html in db. When I want to display it in page all html elements appear in out put. So I want to use this code to solve my problem but not solve it.

Here is my code

Data include {body, name, date} that body save as html

  <div ng-repeat="d in Data">
       <div class='content'>
           <div ng-bind-html-unsafe="d.body">
                 <p>{{d.body}}</p>
           </div>
        </div>
  </div>
2
  • which angular version you are using? you may need to include angular-sanitize Commented Mar 18, 2015 at 9:39
  • ng-bind-html-unsafe has been depecrated in latest version, you need to use $sce service then make html as $sce.trustAsHtml Commented Mar 18, 2015 at 9:40

1 Answer 1

3

In jsfiddle inside an question is using angular 1.1 in which ng-bind-html-unsafe is working.

But currently angular has deprecated ng-bind-html-unsafe from latest version, instead you need to use ng-bind-html then sanitize that url from the angular filter using $sce service and $sce.trustedAsHtml()

Filter

app.filter("sanitize", ['$sce', function($sce) {
        return function(htmlCode){
            return $sce.trustAsHtml(htmlCode);
        }
}]);

HTML

  <div ng-repeat="d in Data">
       <div class='content'>
           <div ng-bind-html="d.body | sanitize">
                 <p>{{d.body}}</p>
           </div>
        </div>
  </div>

For more info refer this SO answer

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

Comments

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.