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

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

问题描述

我的数据库存储产品信息,其中很多信息都组织成列表.我将数据作为 $scope.post 加载到 Angular 中.

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 应用程序中时,它被呈现为文本(即

  • 没有被解析).我知道这可能是出于安全原因,但有什么办法可以解决吗?

    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天全站免登陆