2016-09-26 3 views
0

私はng-repeatを持っていて、ng-repeat にはそれぞれborder-colorがあります。だから私はng-repeatの各要素のスタイルが異なっています

getBgColor()

< div ng-repeat="channel in channelList"> <div ng-style="getBgColor()"> </div 
を使用しているように定義される:私はエラー

$rootScope:infdig] 10 $digest() iterations reached 
を得続ける

  $scope.currentColorIndex = (($scope.currentColorIndex+1) % $scope.radioColors.length); 
     $scope.tileColor = $scope.radioColors[$scope.currentColorIndex].hex; 
     return $scope.tileColor 

私はすべてのng-repeatにするので、エラーを取得していますなぜ私が知っている

反復私は別のオブジェクトを返します。この問題を回避するには何がありますか?

答えて

3

あなたはng-repeatあなたは内側の要素でそれを使用することができ$indexを使用して、そのインデックスを記録するのででも、機能を呼び出す必要がいけません。

<div ng-repeat="channel in channelList"> 
    <div ng-style="{color: radioColors[$index].hex}"> 
</div 

radioColorsスコープオブジェクトであるradioColors[$index].hex式、によって返さヘクスにcolorプロパティを割り当てます。

Just go through this documentation

2

ngRepeatを使用すると、$ indexを使用できます。ここで

<div ng-repeat="channel in channelList"> 
    <div ng-style="getBgColor($index)"> 
</div> 
関連する問題