angularjsngsanitize

How to display formatted html in text area in angularjs?


I am trying to display html by using angularjs sanitize module and ng-bind-html attribute on the element. It works fine if I have the attribute on a div element.

<div ng-bind-html="htmlText" contenteditable="false"></div>

But I need the same text in a text area control. When I read about displaying html in text area, my understanding was that text area does not support this. Is there a way I can convert the html to text before hand in controller and then use only ng-bind on text area? I have multiple long paragraphs and bullet points in html to display as formatted text. Thanks for any suggestions.

//Does not display formatted html.

<textarea class="form-control" ng-bind-html="htmlText" contenteditable="false" rows="7"></textarea>

Solution

  • textarea only supports plain text. Since you are not allowing the text to be edited, I'd use the div that you started with. I suspect that you're trying to control the size and enable scroll bars when necessary on the div, and hoping to get that out of textarea. You'll be much better off just styling the div accordingly.