随着NG绑定-HTML不安全的删除,我怎么注入HTML? [英] With ng-bind-html-unsafe removed, how do I inject HTML?
本文介绍了随着NG绑定-HTML不安全的删除,我怎么注入HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用 $消毒
提供商和 NG-绑定-HTM-不安全
指令,允许我的控制器注入HTML成一个DIV。
不过,我无法得到它的工作。
< DIV NG绑定HTML的不安全={{preview_data preview.embed.html}}>< / DIV>
我发现,这是因为它是从AngularJS删除(感谢)。
但是,如果没有 NG-结合HTML的不安全
,我得到这个错误:结果
<一个href=\"http://errors.angularjs.org/undefined/$sce/unsafe\">http://errors.angularjs.org/undefined/$sce/unsafe
解决方案
- 您需要确保sanitize.js被加载。例如,从<一个加载href=\"https://ajax.googleapis.com/ajax/libs/angularjs/[LAST_VERSION]/angular-sanitize.min.js\">https://ajax.googleapis.com/ajax/libs/angularjs/[LAST_VERSION]/angular-sanitize.min.js
- 您需要包括
ngSanitize
模块的应用
例如:VAR应用= angular.module('对myApp',['ngSanitize']);
- 您只需要使用
NG-绑定-HTML
原始HTML
内容绑定。不需要做任何事情在你的控制器。解析和转换是由ngBindHtml
指令自动完成。 (请仔细阅读本的它是如何工作
部分:的 $ SCE )。所以,你的情况&LT; DIV NG绑定-HTML =preview_data preview.embed.html。&GT;&LT; / DIV&GT;
会做的工作。
I'm trying to use $sanitize
provider and the ng-bind-htm-unsafe
directive to allow my controller to inject HTML into a DIV.
However, I can't get it to work.
<div ng-bind-html-unsafe="{{preview_data.preview.embed.html}}"></div>
I discovered that it is because it was removed from AngularJS (thanks).
But without ng-bind-html-unsafe
, I get this error:
http://errors.angularjs.org/undefined/$sce/unsafe
解决方案
- You need to make sure that sanitize.js is loaded. For example, load it from https://ajax.googleapis.com/ajax/libs/angularjs/[LAST_VERSION]/angular-sanitize.min.js
- you need to include
ngSanitize
module on yourapp
eg:var app = angular.module('myApp', ['ngSanitize']);
- you just need to bind with
ng-bind-html
the originalhtml
content. No need to do anything else in your controller. The parsing and conversion is automatically done by thengBindHtml
directive. (Read theHow does it work
section on this: $sce). So, in your case<div ng-bind-html="preview_data.preview.embed.html"></div>
would do the work.
这篇关于随着NG绑定-HTML不安全的删除,我怎么注入HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文