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

标签 html typescript

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/

相关文章:

javascript - 使用 Rollup 混合默认导出和命名导出

javascript - 我们还需要付出所有努力来为 NPM 预编译软件包吗?

javascript - NestJS无法解析JWT_MODULE_OPTIONS的依赖关系(同样的问题,不同的解决方案)

html - Bootstrap : How to make navbar two layered on small screens

css - HTML:我想创建一个水平居中并从顶部到底部的 DIV

javascript - 自动更改时 onChange 事件不起作用

javascript - jQuery 悬停功能不适用于 ng-repeat Angular 对象

reactjs - React redux 生成的无状态组件性能

javascript - 将鼠标悬停在元素上时触发 javascript

javascript - ES6 使用命名空间动态导入?