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?

2
  • Trying to achieve it using angular 4 :) Commented Nov 28, 2017 at 6:53
  • There are so many answers, read all, you found your solution. Commented Nov 28, 2017 at 6:55

2 Answers 2

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(‘>’)
Sign up to request clarification or add additional context in comments.

1 Comment

Is there any dynamic way of doing it? There might be other html encoded characters in the strings.
1

Try pipe for dynamic encoding html string

stackblitz demo - it's working correct do like this

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.