gpt4 book ai didi

javascript - ng-style 未应用在 Angular ng-repeat

转载 作者:太空宇宙 更新时间:2023-11-04 13:15:59 26 4
gpt4 key购买 nike

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

我在我的 Controller 中更改了我的样式,但它从未应用在当前 View 中...:

我目前对 ng-repeat 的看法:

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

我的 Controller 代码:

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

和默认 Controller 部分:

$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' }
}];

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

奇怪的问题感谢大家

CDT

最佳答案

通常在 ng- 指令(ng-click、ng-show 等)中引用变量时不应使用 {{ }}

你可以把它改成:

ng-style="chambre.style"

或者你可以把它放在一个样式标签中:

style="{{chambre.style}}"

关于javascript - ng-style 未应用在 Angular ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24405400/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com