如何通过AngularJS模板输出html? [英] How to output html through AngularJS template?

查看:31
本文介绍了如何通过AngularJS模板输出html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<h1>{{ revision.title }}</h1>

<div ng-bind-html="revision.content"></div>

标题输出正常,但内容 - 没有.它有一些 html,我收到以下错误:Attempting to use an unsafe value in a safe context. 描述如下:http://docs.angularjs.org/error/$sce:unsafe 这很好,但是我如何输出内容,因为其中会有一些 html,所以我必须将其设置为 {{ revision.content |安全 }} 或 smthn.正确的做法是什么?

The title outputs fine, but the content - doesn't. It's got some html in it and I get the following error: Attempting to use an unsafe value in a safe context. which is being described as so: http://docs.angularjs.org/error/$sce:unsafe and that's fine, but then how can I output the content as there will be some html in it and so I must set it to {{ revision.content | safe }} or smthn. What is the correct way?

AngularJS 版本:1.2

AngularJS version: 1.2

推荐答案

所以修复是这样的:

包含来自 http://code.angularjs.org 的 angular-sanitize.min.js/ 并将其包含在您的模块中:

include angular-sanitize.min.js from http://code.angularjs.org/ and include it in your module:

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

然后你可以自由使用 ng-bind-html

这篇关于如何通过AngularJS模板输出html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆