I want to access the index of dashboardCtrl.labels in dashboardCtrl.labelColors which is another array.I have tried the following but no success. If I print just {{$index}} it is getting printed successfully}}
我想要访问dashboardCtrl的索引。在dashboardCtrl标签。标签颜色是另一个数组。我试过以下方法,但没有成功。如果我只打印{$index}它将被成功打印}}
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[{{$index}}]}}</label>
</div>
2 个解决方案
#1
2
Do the following. Just $index
in {{dashboardCtrl.labelColors[$index]}}
instead of {{dashboardCtrl.labelColors[{{$index}}]}}
执行以下操作。美元指数在{ { dashboardCtrl。labelColors[美元指数]} },而不是{ { dashboardCtrl.labelColors[{ {美元指数} }]} }
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[$index]}}</label>
</div>
EDIT
编辑
Apply CSS style attribute dynamically in Angular JS
在有棱角的JS中动态应用CSS样式属性
ng-style="{'background-color': dashboardCtrl.labelColors[$index]}"
#2
3
You don't need nested brackets {{ }}. Try this
不需要嵌套括号{}。试试这个
<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
Do the following. Just $index
in {{dashboardCtrl.labelColors[$index]}}
instead of {{dashboardCtrl.labelColors[{{$index}}]}}
执行以下操作。美元指数在{ { dashboardCtrl。labelColors[美元指数]} },而不是{ { dashboardCtrl.labelColors[{ {美元指数} }]} }
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[$index]}}</label>
</div>
EDIT
编辑
Apply CSS style attribute dynamically in Angular JS
在有棱角的JS中动态应用CSS样式属性
ng-style="{'background-color': dashboardCtrl.labelColors[$index]}"
#2
3
You don't need nested brackets {{ }}. Try this
不需要嵌套括号{}。试试这个
<div class="row" ng-repeat="i in dashboardCtrl.labels">
<div id="circle" style="background:green"></div>{{i}}
<label>{{dashboardCtrl.labelColors[$index]}}</label>
</div>