ng-style not applied在角度ng-repeat中

时间:2014-06-25 09:49:52

标签: javascript css angularjs

我在使用Angular.js和ng-switch指令时遇到了问题。

我在我的控制器中更改了我的风格,但它从未在当前视图中应用...:

我目前使用ng-repeat视图:

<button class="btn btn-default btn-lg" type="button" ng-repeat="chambre in spooler" ng-style="{{chambre.style}}">{{chambre.libelle}}</button>

我的控制器代码:

$scope.spooler[id]["style"] = { 'background-color' : code_couleur  };

默认控制器部分:

$scope.spooler = [{
                idt_zones : "1",
                libelle : "100",
                id_etat : 1,
                style: { 'background-color' : '#DE8C00' }
            }, {
                idt_zones : "2",
                libelle : "101",
                id_etat : 2,
                style: { 'background-color' : '#00983D' }
            }, {
                idt_zones : "3",
                libelle : "102",
                id_etat : 3,
                style: { 'background-color' : '#B9121B' }
            }];

当我想要更改元素的样式时,背景颜色会在页面的源代码中发生变化,但它从未应用于视图中的元素。

奇怪的问题 谢谢大家

CDT

2 个答案:

答案 0 :(得分:1)

一般来说,在引用ng-指令(ng-click,ng-show等)中的变量时,不应使用{{}}

您可以将其更改为:

ng-style="chambre.style"

或者你可以把它作为样式标签:

style="{{chambre.style}}"

答案 1 :(得分:0)

它应该是ng-style="chambre.style"See documentation

相关问题