Vivendi
Vivendi

Reputation: 20997

Supress ngBindHtml error in AngularJS

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?

Upvotes: 3

Views: 4505

Answers (1)

tdakhla
tdakhla

Reputation: 670

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

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

More info on $sce

Upvotes: 6

Related Questions