json - Angular.js 解析 JSON 中的 html 标签

标签 json angularjs angular-filters

是否可以解析 JSON 值中的 html 标签?可能是通过过滤器?我有以下 JSON。

{
    "title" : "Auto Donation Program",
    "shortname" : "auto_donation_program",
    "summary": "Donated vehicles find new homes through this program. Recipients are eligible to apply if they have been actively participating at Vineyard Cincinnati or The Healing Center under the guidelines of the program for six months.",
    "description" : "<h2>Give your automobile to a new home to help a family in need</h2><p>Please contact Deena Casagrande at (513) 346-4080 Ext. 207 to make arrangements for auto donations. Please do not drop your car off in the parking lot.</p><h2>Tax Benefits</h2><p>It seems that every non-profit these days is encouraging you to donate your vehicle to charity and \"get a tax deduction.\" But there’s a simple distinction between donating your car to The Healing Center versus donating it almost anywhere else.</p><p>As of January 1, 2005, the rules on how much you can write off your taxes were tightened. If the organization sells your car, as most do, you can deduct only the amount they sold it for--and they may sell it for far less than it’s worth. However, if the organization gives your car to someone who will drive it, as The Healing Center does, you can claim full Blue Book value--a significant difference on your taxes. (It’s important to note that when you donate a vehicle, you receive a tax deduction, not a tax credit.)</p><h2>So where does your car end up? </h2><p>Those on the receiving end of The Healing Center’s auto donation program must fill out a detailed questionnaire, meet the eligibility requirements of the program, and be approved by the Benevolence Review Team. Vehicles are given to single parent families or individuals needing transportation for employment or who are enrolled in school to obtain employment.</p>"
  } 

在我的模板中显示为:
<p>{{service.description}}</p>

最佳答案

这对我有用:

<div ng-bind-html="'{{service.description}}' | to_trusted"></div>

筛选
angular.module('app')
.filter('to_trusted', ['$sce', function($sce){
    return function(text) {
        return $sce.trustAsHtml(text);
    };
}]);

关于json - Angular.js 解析 JSON 中的 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24682694/

相关文章:

java - 我的字符串编码内部 JSON 文档的 Gson 解析错误

javascript - 从 Javascript-Object 生成表单

c# - 无法解析 JSON 文件,Progam.cs asp.net core 中出错

angularjs - 使用 JavaScript 将西里尔字母大写

javascript - AngularJS 按代码过滤

javascript - AngularJS:将数组打印为字符串的好方法

javascript - 广度优先遍历对象

javascript - 如何在 froala 编辑器中禁用表情符号

javascript - Angular 和内置的 javascript 映射函数

javascript - AngularJS 用函数调用数组