AngularJS - 是否可以使用 ng-repeat 来呈现 HTML 值? [英] AngularJS - Is it possible to use ng-repeat to render HTML values?

查看:26
本文介绍了AngularJS - 是否可以使用 ng-repeat 来呈现 HTML 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆