如何在 angular.js 中的 ng-repeat 中解析 HTML [英] How to parse HTML in ng-repeat in angular.js
问题描述
我需要在 ng-repeat 中从我的模型中解析可选的 HTML.
I need to parse optional HTML from my model in ng-repeat.
我在 .jade 模板中有一个中继器,如下所示:
I have a repeater in a .jade template like this:
tr(ng-repeat='car in cars')
td(class='arrived-{{car.arrived}}') {{car.number}}
td(class='arrived-{{car.arrived}}') {{car.location}}
我的 car.location 可以是纯文本,例如:
my car.location can be plain text like:
城市名称
或者它可以包含一些 html,如下所示:
or it can have some html in it, like this:
In transit, <a href="http://example.com/"/>view</a>
现在,当我得到 HTML 时,它不会被解析.不幸的是,数据来自第三方站点,所以我无法影响它.是否有指令或过滤器可以将其转换为有效链接?
Now, when I get the HTML, this doesn't get parsed. The data is unfortunately from a third party site, so I can't influence that. Is there a directive or filter that could turn this into a valid link?
如果没有,我还能尝试用它做什么?
If not, what else could I try to do with it?
推荐答案
你需要的是 ng-bind-html-unsafe
.它正确解析 HTML ;)
What you need is ng-bind-html-unsafe
.
It parses the HTML correctly ;)
<p ng-bind-html-unsafe="car.location"></p>
这个问题似乎也与此类似:parse html inside ng-bind usingangularJS
Also this question seems similarly to this: parse html inside ng-bind using angularJS
这篇关于如何在 angular.js 中的 ng-repeat 中解析 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!