简体   繁体   中英

Display HTML tags a string in inner html tag

I want to display html tags in string format in inner html tag

I have following string

myString = "<span class="display-red"><a href="link"><span>ABC <a href=""></a>PQR</span><span>abc@gmail.com</span></a></span>"

This is my html tag in code (Here I want to render this html tag)

<span [innerHtml]="myString"></span>

Expected Output

ABC <a href=""></a>PQR
abc@gmail.com

I want to display some html tag as it is in my output.

In the html you want to display, replace < with &lt; (or > with &gt; )

 myString = "<span class="display-red"><a href="link"><span>ABC &lt;a href="">&lt;/a>PQR</span><span>abc@gmail.com</span></a></span>"

Use &lt; instead of < and &gt; instead of > . You will get exactly what you want.
Solution:

myString = "<span class="display-red"><a href="link"><span>ABC &lt;a href=""&gt;&lt;/a&gt;PQR</span><span>abc@gmail.com</span></a></span>"

You should replace the < with &lt; and the > with &gt; . This will display it as regular text.

You should replace the < with < and the > with >

myString = "<span class="display-red">ABC <a href="link"><span>&lt;a href=""&gt;&lt;/a&gt;</a>PQR</span><br><span>abc@gmail.com</span></span>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM