Angular sanitize/ng-bind-html 不起作用? [英] Angular sanitize / ng-bind-html not working?

查看:21
本文介绍了Angular sanitize/ng-bind-html 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个中继器,只要其中没有 html,就可以显示数据.

I've got a repeater set up and can get data to display as long as there is no html within it.

我已经包含了 angular-sanitize.js 并尝试使用 ng-bind-html

I've included angular-sanitize.js and have tried using ng-bind-html

但是跨度内没有显示任何内容,仅在 ng-bind-html 属性内显示.所以看起来消毒不起作用,

But nothing is displayed within the span, only within the ng-bind-html attribute. So it looks like sanitise isn't working,

我读到这需要添加到应用程序依赖项中,但不确定在哪里添加.

I read that this needs to be added to the app dependencies but am not sure where to do so.

我刚刚在 angular 站点上完成了 tut 工作,所以现在只设置了一个非常基本的控制器.

I've just been working through the tut on the angular site so only have a very basic controller set up at the minute.

推荐答案

  1. 您需要包含 angular-sanitize.jshttp://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js

ngSanitize"添加到您的模块依赖项

Add 'ngSanitize' to you module dependencies

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

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

  • 不要在属性中使用{{}}

    <h1 ng-bind-html="item.title"></h1>

    <h1 ng-bind-html="item.title"></h1>

  • 不要使用$sce.trustAsHtml()

    这篇关于Angular sanitize/ng-bind-html 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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