Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - Is it possible to use ng-repeat to render HTML values?

I'm using AngularJS with a third party service that generates html responses. I want to use ng-repeat to render the HTML responses as a list, however Angular renders it as text.

Is it possible to use ng-repeat to render HTML property?

I've created this jsFiddle to demonstrate my issue. http://jsfiddle.net/DrtNc/1/

like image 470
Shlomi Schwartz Avatar asked Jul 10 '12 07:07

Shlomi Schwartz


3 Answers

I think using ng-bind-html-unsafe will get you what you need.

<div ng:repeat="item in items" ng-bind-html-unsafe="item.html"></div>

Here's a working fiddle: http://jsfiddle.net/nfreitas/aHfAp/

Documentation for the directive can be found here: http://docs.angularjs.org/api/ng.directive:ngBindHtmlUnsafe

like image 72
Noah Freitas Avatar answered Nov 11 '22 09:11

Noah Freitas


The way I achieved this is by ng-bind-html inside the ng-repeat;

<div ng-repeat="comment in comments">
  <div ng-bind-html="comment.content"></div>
</div>

Hope this helps someone!

like image 17
Matt Saunders Avatar answered Nov 11 '22 09:11

Matt Saunders


item.html will always be interpreted as text. you have to convert it to html explicitly. click here

I have added a render function which will convert each string to html.

like image 2
Kishore Avatar answered Nov 11 '22 09:11

Kishore