3

I need to parse optional HTML from my model in ng-repeat.

I have a repeater in a .jade template like this:

tr(ng-repeat='car in cars')
  td(class='arrived-{{car.arrived}}') {{car.number}}
  td(class='arrived-{{car.arrived}}') {{car.location}}

my car.location can be plain text like:

City name

or it can have some html in it, like this:

In transit,  <a href="http://example.com/"/>view</a>

Now, when I get the HTML, this doesn't get parsed. The data is unfortunately from a third party site, so I can't influence that. Is there a directive or filter that could turn this into a valid link?

If not, what else could I try to do with it?

Charles
  • 50,943
  • 13
  • 104
  • 142
Zlatko
  • 18,936
  • 14
  • 70
  • 123
  • Thanks for marking it duplicate, @georgeawg. Out of curiosity - how do you decide which question is a duplicate of what? E.g. this one is from 2013, the linked answer is from 2016, so it's clearly not by age. – Zlatko Jul 24 '18 at 14:18
  • The answer here is obsolete and no longer works. The `ng-bind-html-unsafe` directive was removed from AngularJS for security reasons. – georgeawg Jul 24 '18 at 14:47
  • Thanks. That makes sense. – Zlatko Jul 25 '18 at 06:00

1 Answers1

7

What you need is ng-bind-html-unsafe. It parses the HTML correctly ;)

Example: http://jsbin.com/ubujem/1/

<p ng-bind-html-unsafe="car.location"></p>

Also this question seems similarly to this: parse html inside ng-bind using angularJS

Community
  • 1
  • 1
AndreM96
  • 1,355
  • 1
  • 23
  • 34