gpt4 book ai didi

html - 如何在 typescript 中使用/显示带有html标签的字符串

转载 作者:行者123 更新时间:2023-12-05 03:01:55 34 4
gpt4 key购买 nike

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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com