防止 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.
我正在构建的应用程序需要用户创建模板,使用大括号表示法插入变量名称,我不想通过为某些变量引入指令并为其他变量引入花括号来使其过于复杂.
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屋!