2017-04-27 80 views
2

我想访问dashboardCtrl.labelColors中另一个数组的dashboardCtrl.labels的索引。我尝试了以下但未成功。如果我只打印{{$指数}}是越来越成功打印}}访问另一个数组的一个数组的索引

<div class="row" ng-repeat="i in dashboardCtrl.labels"> 
           <div id="circle" style="background:green"></div>{{i}} 
           <label>{{dashboardCtrl.labelColors[{{$index}}]}}</label> 
          </div> 
+1

尝试只指数不{{指数}} – Jenny

回答

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> 

编辑

在角JS动态应用CSS样式属性

ng-style="{'background-color': dashboardCtrl.labelColors[$index]}" 
+0

是的,这解决了我的问题这是动态分配样式的相同方式

{{i}} – Delfin

+0

我们使用ng样式。我在答案的编辑部分添加了一个小型演示。 – Rakeschand

+0

明白了吧..当场! – Delfin

3

你不需要嵌套括号{{}}。试试这个

<div class="row" ng-repeat="i in dashboardCtrl.labels"> 
    <div id="circle" style="background:green"></div>{{i}}        
    <label>{{dashboardCtrl.labelColors[$index]}}</label> 
</div> 
相关问题