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

标签 javascript html angularjs

我必须通过 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/

相关文章:

AngularJs 指令命名约定

css - Angularjs ng-class多类

asp.net - 在 VS Code 和 VS 2015 之间切换

javascript - 当 opacity=false 时,图像流动画在 IE 上看起来很糟糕

javascript - Javascript 修改 CSS 时的 CSS 特异性?

html - 第 n 个类型未按预期工作

html - 具有 anchor 悬停状态的未知尺寸的垂直/水平居中图像

javascript - 如何从nodejs回调函数返回值?

javascript - 如何访问 HTML 表格单元格中的选择

javascript - BXSlider 4 在移动设备上全屏 : How to keep native vertical page scroll (up, 向下)但保持水平触摸功能(左、右)?