1

I am trying to add the following code.

$scope.journals = [
   {title: "Journal", content: "This is content <br>"}
]

The HTML that I have is:

<div ng-repeat="journal in journals">
   <h1>{{journal.title}}</h1>
   <span>{{journal.content}}</span>
</div>

However the "br" Tag is showing as just plain text and not html. How can I fix that?

Chase W.
  • 1,343
  • 2
  • 13
  • 25

3 Answers3

1

if you don't want to mess with $sce and you just want to get er done:

lrApp.directive('bindHtml', function () {
return {
    restrict: 'A',
    link: function (scope, elem, attrs) {
        scope.$watch(attrs.bindHtml,function(nv,ov){
            elem.html(nv);
        });
    }
};
});
btm1
  • 3,866
  • 2
  • 23
  • 26
0

Not sure if this can work for you but you can use a combination of ng-bind-html with $sce.trustAsHtml() to mark your content as trusted. Note that you'll only want to do this if you can truly consider the content as safe.

Here's a plunk as an example:

http://plnkr.co/edit/L51T4OxdF8AFF5lRQdQW

Here's the $sce documentation. Worth a read IMHO to understand the impact of trustAs.

https://docs.angularjs.org/api/ng/service/$sce

brianmarco
  • 343
  • 1
  • 8
0

You just need to use ng-bind-html directive, provided by angularjs

<span ng-bind-html="journal.content"></span>
Sericaia
  • 450
  • 3
  • 15