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

前端 未结 3 976
耶瑟儿~
耶瑟儿~ 2020-12-15 20:11

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

相关标签:
3条回答
  • 2020-12-15 20:55

    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

    0 讨论(0)
  • 2020-12-15 20:59

    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.

    0 讨论(0)
  • 2020-12-15 21:10

    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!

    0 讨论(0)
提交回复
热议问题