简体   繁体   English

防止 Angular 转义 HTML

[英]Prevent Angular from escaping HTML

When Angular interpolates markup and inserts scoped variables into a {{post}} style template, it escapes HTML.当 Angular 插入标记并将作用域变量插入{{post}}样式模板时,它会转义 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.我正在构建的应用程序要求用户创建模板,使用花括号符号插入变量名称,我不想通过为某些变量引入指令而为其他变量引入指令来使其过于复杂。

Is there a way to render non escaped HTML through curly templates?有没有办法通过卷曲模板呈现非转义 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.我唯一的选择是在用户尝试呈现{{post}}时呈现代理元素,然后我可以使用 jQLite 抓取它并手动插入 HTML,但这一切都是混乱的。 Any ideas?有任何想法吗?

Your going to want to look at ngBindHtml .你会想看看ngBindHtml

"To utilize this functionality, ensure that $sanitize is available, for example, by including ngSanitize in your module's dependencies (not in core Angular.)" “要利用此功能,请确保 $sanitize 可用,例如,通过在模块的依赖项中包含 ngSanitize(而不是在核心 Angular 中)。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM