要在Angular中使用带有样式的innerHtml,可以使用以下解决方法:
import { Component } from '@angular/core';
@Component({
selector: 'app-example',
template: `
`
})
export class ExampleComponent {
htmlWithStyle: string = 'Hello, World!
';
}
[innerHtml]
指令将属性绑定到HTML元素的innerHtml属性上。请注意,使用这种方法可能存在安全风险,因为它可以允许动态注入恶意脚本。因此,建议对输入进行适当的验证和过滤,以确保安全性。