var bannerText = stringFormat("This is my {0}test content{1} here", "<b>", "</b>");
<div>
<p> {para1}</p>
<p> {bannerText}</p>
</div>
html 标签被打印而不是将它们作为文本应用
观察输出
This is my <b>test content</b> here
需要输出
This is my test content here
最佳答案
<div [innerHTML]="bannerText"></div>
但是,请记住 Angular 的 docs about security ,上面写着 Angular recognizes the value as unsafe and automatically sanitizes it, which removes the <script> tag but keeps safe content such as the <b> element.
.
关于html - 如何在 typescript 中使用/显示带有html标签的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369816/