Supress ngBindHtml error in AngularJS

和自甴很熟 提交于 2019-12-07 12:33:41

问题


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.

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>.

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?


回答1:


Simply use a filter that calls $sce.trustAsHtml to get around any parsing errors.

Fiddle: http://jsfiddle.net/95yomb4y/

More info on $sce



来源:https://stackoverflow.com/questions/26069145/supress-ngbindhtml-error-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!