3

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?

Vivendi
  • 20,047
  • 25
  • 121
  • 196

1 Answers1

6

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

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

More info on $sce

Aravind
  • 40,391
  • 16
  • 91
  • 110
tdakhla
  • 670
  • 4
  • 4
  • 4
    It is not really the sollution. If user create this content it means that it is not safe ! If you use trustAsHtml you can inject dangerous content. – Łukasz Ł Sep 24 '15 at 12:37