【问题标题】:Angular filter for HTML formatting用于 HTML 格式的 Angular 过滤器
【发布时间】:2015-11-23 07:55:34
【问题描述】:

是否有用于使 JSON 数据显示为格式化 HTML 的现有角度过滤器?

来自控制器的 JSON 数据:

{ data: 'This data is <b>bold</b>' }

HTML:

<div>{{data | someKindOfFormatFilter }}</div>

想要的结果:

此数据粗体

【问题讨论】:

  • 你想用过滤器绑定HTML吗?
  • &lt;div ng-bind-html='data'&gt;&lt;/div&gt;一样使用ng-bind-html
  • 你可以使用 ng-style 和 ng-class 指令
  • @SameerK ng-bind-html 给我一个错误:错误:[$sce:unsafe] Attempting to use an unsafe value in a safe context。
  • stackoverflow.com/questions/19770156/… 处查看最后 2 个答案以解决问题。

标签: angularjs html


【解决方案1】:

我最终按照 SameerK 的建议使用 ngSanitizeng-bind-html

var app = angular.module('app', ['ngSanitize']);

在这篇文章中回答: How to output html through AngularJS template?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2014-08-11
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 2015-01-12
    相关资源
    最近更新 更多