1

For a personal testbed project, I'm using Angular to create a small website, to show off a small game project I am working on.

One of the things I am trying to do is to make the blog entries be driven by a JSON blob. As I update the blob, people who view the Blog path of the SPA will see the updated content.

However...the HTML tags in the HTML part of the blob are rendering as clear text!

Here is my not-so-working plunker.

This is probably a very basic mistake I am making. My question: what do I do with the data I'm getting back from the $http get's fulfilled promise, to make the HTML in the JSON blob properly render as HTML, instead of as raw text?

Andrew Gray
  • 3,756
  • 3
  • 39
  • 75

2 Answers2

3

HTML is escaped (<br> becomes something like &lt;br&gt;) when it comes in via JSON. You need to download and inject the HTML Sanitizer.

https://docs.angularjs.org/api/ngSanitize

The Head Rush
  • 3,157
  • 2
  • 25
  • 45
  • http://plnkr.co/edit/dODIHaACiEBBGp1w4dQ0?p=preview - I tried to implement the ngSanitize module, but it's really not working so well. What am I missing? – Andrew Gray Aug 27 '14 at 20:22
  • When i had to do something similar, i got it working with help from this post, using the filter method halfway down or so. http://stackoverflow.com/questions/18340872/how-do-you-use-sce-trustashtmlstring-to-replicate-ng-bind-html-unsafe-in-angu – The Head Rush Aug 27 '14 at 20:45
0

try this plunker http://plnkr.co/edit/JCG684ECgfnE4aB0kphT?p=preview`

or follow angular doc for ng-bind-html

ABOS
  • 3,723
  • 3
  • 17
  • 23