I have a data source that contains an array of raw HTML strings. I have to display them on the page to the user.
Being a little new with Angular, the first thing I tried was this:
<div ng-repeat="html in ctrl.html" ng-bind="html"></div>
This causes Angular to leave my HTML code and display it as a string. This is not what I need, but at least it shows that Angular is really loading data.
When doing a Google search, I read about the ng-bind-html-unsafe directive, which, as I understand it, should enter text into an HTML document, without avoiding or sanitizing it in any way that I want, because I have to trust our data source.
<div ng-repeat="html in ctrl.html" ng-bind-html-unsafe="html"></div>
This does not work either. It just shows me a blank page. When I open the document inspector, I see that for each entry in the HTML array there is a div tag, but all fields are empty.
By doing more of Google-fu, I found discussions about method calls in $ scope to make Angular good with this. They say that ng-bind-html-unsafe is deprecated.
With all the talk about different ways to do what I need with different versions of Angular, how to do it with today's version: 1.4?
source
share