AngularJS - 渲染HTML标签包含在一个字符串 [英] AngularJS - Render HTML tags that are contained in a string

查看:998
本文介绍了AngularJS - 渲染HTML标签包含在一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库存储产品信息,和大量的这种被组织成列表。我加载数据到作为角 $ scope.post

My database stores product information, and a lot of this is organised into lists. I load the data into Angular as $scope.post.

例如,

$scope.post.size_description = '<li> Fits true to size. Take your normal size\r</li>
   <li> Slim-cut, mid-rise style</li>
   <li> Long in length, alter to fit</li>
   <li> Model wears an IT 48\r</li>
   <li> Model measures: waist size 32, height 6\'1"/ 185cm\r</li>'.

当我尝试这个数据加载到我的角的应用程序,它就会呈现为文本(即&LT;立GT; 不被解析)。我理解这可能会发生出于安全原因,但有周围没有任何办法吗?

When I try to load this data into my Angular app, it gets rendered as text (i.e. the <li> are not parsed). I understand this probably happens for security reasons, but is there any way around it?

推荐答案

由于Damax在这里说: http://stackoverflow.com / A /七十六万九千零八十三分之一千一百六十四万零四百二十○

As Damax has said here: http://stackoverflow.com/a/11640420/769083

<div ng-bind-html-unsafe="post.size_description"></div>

这篇关于AngularJS - 渲染HTML标签包含在一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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