AngularJS - 是否可以使用 ng-repeat 来呈现 HTML 值? [英] AngularJS - Is it possible to use ng-repeat to render HTML values?
问题描述
我将 AngularJS 与生成 html 响应的第三方服务一起使用.我想使用 ng-repeat 将 HTML 响应呈现为列表,但 Angular 将其呈现为文本.
是否可以使用 ng-repeat 来渲染 HTML 属性?
我创建了这个 jsFiddle 来演示我的问题.http://jsfiddle.net/DrtNc/1/
我认为使用 ng-bind-html-unsafe
可以满足您的需求.
<div ng:repeat="item in items" ng-bind-html-unsafe="item.html"></div>
这是一个有效的小提琴:http://jsfiddle.net/nfreitas/aHfAp/>
指令的文档可以在这里找到:http://docs.angularjs.org/api/ng.directive:ngBindHtmlUnsafe
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/
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
这篇关于AngularJS - 是否可以使用 ng-repeat 来呈现 HTML 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!