我想在dashboardCtrl.labelColors中访问dashboardCtrl.labels的索引,这是另一个数组。我尝试了以下但没有成功。如果我只打印{{$ index}},则会成功打印}}
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[{{$index}}]}}</label>
</div>
答案 0 :(得分:3)
您不需要嵌套括号{{}}。试试这个
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[$index]}}</label>
</div>
答案 1 :(得分:2)
执行以下操作。只需$index
{{dashboardCtrl.labelColors[$index]}}
而不是{{dashboardCtrl.labelColors[{{$index}}]}}
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[$index]}}</label>
</div>
修改强>
在Angular JS中动态应用CSS样式属性
ng-style="{'background-color': dashboardCtrl.labelColors[$index]}"