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

查看:496
本文介绍了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>'.

当我尝试将这些数据加载到我的Angular应用程序中时,它会被渲染为文本(即< li> 不会被解析)发生安全的原因,但是有没有办法?

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在这里所说: https://stackoverflow.com/a/11640420/769083

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

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

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

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