防止Angular转义HTML [英] Prevent Angular from escaping HTML
问题描述
当Angular插入标记并将范围变量插入 {{post}}
样式模板时,它会转义HTML。
When Angular interpolates markup and inserts scoped variables into a {{post}}
style template, it escapes HTML.
我正在构建的应用程序需要用户创建模板,使用大括号表示法来插入变量名称,我不想通过为某些变量引入指令和对其他变量进行curlies来使其复杂化。
The application I'm building requires users to create the templates, using curly brace notation to insert variable names, I don't want to overcomplicate it by bringing in directives for some variables and curlies for others.
有没有办法通过卷曲模板呈现非转义HTML?
Is there a way to render non escaped HTML through curly templates?
我唯一的选择是在用户呈现代理元素尝试渲染 {{post}}
,然后我可以用jQLite抓取并手动插入HTML,但这都是凌乱的阴影。有什么想法吗?
My only alternative is to render a proxy element when the user attempts to render {{post}}
, which I can then grab with jQLite and insert the HTML by hand, but that is all shades of messy. Any ideas?
推荐答案
你想看看 ngBindHtml 。
要使用此功能,请确保$ sanitize可用,例如,在模块的依赖项中包含ngSanitize(不在核心Angular中。)
"To utilize this functionality, ensure that $sanitize is available, for example, by including ngSanitize in your module's dependencies (not in core Angular.)"
这篇关于防止Angular转义HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!