问题
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