AngularJS中的Supress ngBindHtml错误 [英] Supress ngBindHtml error in AngularJS
问题描述
我有一个文本区域,用户可以在其中创建自己的文本,也可以使用HTML.键入时,文本区域中的文本会立即显示在DIV
中.
I have a textarea where users can create their own text and are also allowed to use HTML. The text from the textarea is immidiately displayed in a DIV
as they type.
DIV
上具有ng-bind-html
属性.因此,它尝试解析每个更改.假设用户要键入Hello <strong>world</strong>
.
The DIV
has the ng-bind-html
attribute on it. So it tries to parse every single change. Suppose the user wants to type Hello <strong>world</strong>
.
如果用户在文本区域中键入 Hello ,则一切正常.但是,只要他们键入第一个<
,那么ngSanitize
就会开始抱怨Error: [$sanitize:badparse] ...
.我觉得这很烦人.我可以想象,在某些情况下,对此进行提醒很方便.但就我而言,我不需要这些错误.
If the user types Hello in the textarea then all goes fine. But as soon as they type the first <
then ngSanitize
starts to complain about Error: [$sanitize:badparse] ...
. I find this annoying. I can imagine that in some cases it's handy to be alerted about this. But in my case I don't need the errors.
反正有什么要抑制或禁用它们的?
Is there anyway to supress or disable them?
推荐答案
只需使用调用$sce.trustAsHtml
的过滤器来解决所有解析错误.
Simply use a filter that calls $sce.trustAsHtml
to get around any parsing errors.
提琴: http://jsfiddle.net/95yomb4y/
这篇关于AngularJS中的Supress ngBindHtml错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!