如何在从 json 获取样式时使用 ng-style



这是我的代码

这是我的代码ng-style="background: {{x.background}}"

什么渲染ng-style="background: #f4f4f4"

我期待style="background: #f4f4f4"

我认为正确的指令是ng-attr-style,检查文档

试试这个:

ng-style="{ background: x.background}"

这更类似于 json。事实上,你可以有一个json对象并直接使用它。

更改此设置

ng-style="background: {{x.background}}"

ng-attr-style="background: {{x.background}}"

最新更新