gpt4 book ai didi

javascript - 如何制作 ng-bind-html angularjs 代码

转载 作者:行者123 更新时间:2023-12-03 03:56:08 25 4
gpt4 key购买 nike

我必须通过 Angullar js 数据传递 html 代码

 this.items = [
{
'title': 'Angular',
'icon': 'angular',
'description': " <ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul>A powerful Javascript framework for building single page apps. Angular is open source, and maintained by Google.",
'color': '#E63135'
},
{
'title': 'CSS3',
'icon': 'css3',
'description': '<ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul> The latest version of cascading stylesheets - the styling language of the web!',
'color': '#0CA9EA'
},
{
'title': 'HTML5',
'icon': 'html5',
'description': 'The latest version of the web\'s markup language.',
'color': '#F46529'
},]

bu在 View html中

{{item.description}}

不工作

ng-bind-html="item.description"
不工作

最佳答案

“默认情况下,将使用 $sanitize 服务清理生成的 HTML 内容。要使用此功能,请确保 $sanitize 可用” 为了在模块的依赖项中使用 ngSanitize,您需要在应用程序中包含“angular-sanitize.js”。

您还可以绕过对您知道安全的值的清理。为此,请通过 $sce.trustAsHtml 绑定(bind)到显式可信值。请参阅严格上下文转义 (SCE) 下的示例。

https://docs.angularjs.org/api/ng/directive/ngBindHtml

https://docs.angularjs.org/api/ng/service/ $sce#show-me-an-example-using-sce-

关于javascript - 如何制作 ng-bind-html angularjs 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44938893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com