【发布时间】:2019-06-12 00:02:57
【问题描述】:
如何获取字符串中的 CSS 以动态绘制 HTML 元素?
HTML 元素必须动态呈现一行 CSS 代码。
使用[style.etc]、[ngStyle]、[style]、[ngStyle]、[ng-class] 对我不起作用,因为我从后端收到带有 CSS 代码的字符串,例如:
风格:"background: red; color: white;"
我无法使用以下解决方案:
style: "{{style}}" 也不是 [style] = "style" 因为我在控制台中收到一条警告:
警告:清理不安全的样式值背景:网络;颜色:白色;
<button type="button"
*ngFor="let controlHTML of buttons"
style="{{controlHTML.attributes.style}}"> HelloWorld
</button>
【问题讨论】:
标签: css angular dynamic styles rendering