RooksStrife
RooksStrife

Reputation: 1747

Angular 7 - Encoding and Decoding HTML Entities In [(ngModel)]

I am having an issue with encoding and decoding HTML Entities on a textarea using ngModel. The Back-End needs and is sending the ><"&' as HTML Entities. This seems like it would be easy to do this, but for the life of me I can't think of a straight/safe way to do it.

  1. I need to get the data from the Back-End and render the entities as normal text to the user.

  2. On save - I need to send back to the back-end the special characters of ><"&' as entities.

  3. Bonus if there is a way to do a blanket on all special characters - not needed, but why not.

    <textarea class="form-control" rows="5" id="comment" [(ngModel)]="employee.comments">

Upvotes: 1

Views: 2171

Answers (1)

MahanteshGowda Patil
MahanteshGowda Patil

Reputation: 141

You can use innerhtml to load html content

<textarea class="form-control" rows="5" id="comment"  [innerHtml]="employee.comments" [(ngModel)]="employee.comments">

you can refer this for more information.

Similar query answer. Alternative way NPM Package

Upvotes: 1

Related Questions