简体   繁体   English

显示 HTML 标签内部 html 标签中的字符串

[英]Display HTML tags a string in inner html tag

I want to display html tags in string format in inner html tag我想在内部 html 标签中以字符串格式显示 html 标签

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)这是我在代码中的 html 标签(这里我想渲染这个 html 标签)

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

Expected Output预计 Output

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

I want to display some html tag as it is in my output.我想显示一些 html 标签,因为它在我的 output 中。

In the html you want to display, replace < with &lt;在你要显示的html中,将<替换为&lt; (or > with &gt; ) (或>&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;使用&lt; instead of < and &gt;而不是<&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;您应该将<替换为&lt; and the > with &gt;>&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>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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