0

I have a very simple requirement. I have two strings as follows :

htmlStr = "<strong>News Body</strong>";
htmlStr1 = "<strong>News Body2</strong>";

I use innerHTML of div tag to display these strings on a html page

<div [innerHTML]="htmlStr"></div>
<div [innerHTML]="htmlStr1"></div>

Output I get is

enter image description here

My expected output is :

enter image description here

How do i remove html encoding from htmlStr?

Ankit Singh
  • 272
  • 5
  • 15
Mandar Patil
  • 538
  • 2
  • 10
  • 29

2 Answers2

1

The output is correct. You should replace the special characters with the brackets by e.g.

strHtml = strHtml.split(‘&lt;’).join(‘<‘).split(‘&gt;’).join(‘>’)
Alexander Elgin
  • 6,796
  • 4
  • 40
  • 50
1

Try pipe for dynamic encoding html string

stackblitz demo - it's working correct do like this

Chandru
  • 10,864
  • 6
  • 38
  • 53