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>
br.julien
  • 3,420
  • 2
  • 23
  • 44
Hadi J
  • 16,989
  • 4
  • 36
  • 62

1 Answers1

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

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299