2017-02-28 6 views
2

いつも$index === 0ではないng-if条件を通過する最初のインデックスを探しており、$firstを使用して解決できません。私はitemの最初の出現にクラスを追加したいAngularJS:ng-repeatの最初の要素にCSSクラスを適用します。

<div class="ticket-event" ng-if="!item.hidden" ng-repeat="item in ctrl.event.items"> 
    <div class="title item" ng-class="{'active': $index === $first}"></div> 
</div> 

は、ここに私のコードサンプルです。

答えて

2

なぜCSSでこれをしないのですか?

.ticket-event div:first-child { // css here } 
ここ
2

は、あなたが何をする必要があるかです::

<div class="title item" ng-class='{active:$first}'></div> 
CSSは簡単です、スペルの間違いであり、それは「チケット・イベント」でなければなりません「-eventチケット」を仮定し

<div class="title item" ng-class="{'active': $index === $first}"> 

変更:$indexがで$firstある場合

4

かを確認する必要はありませんそれへ:

<div class="title item" ng-class="{'active': $first}"> 
+0

しかし、2行目を通過したアイテムインデックスが0から始まらなかった場合、5と言うと、$ firstディレクティブは機能しません –

-1

これは私のため

これは私のために働いてい
<div class="title item" ng-class='{active:$first}'></div> 
0
<tr ng-class="{evaluationRow : $index==0 && item.HighlightBorder==true }" ng-repeat="item in items" >  
       <td>{{item.LearnerId}} </td> 
       <td>{{item.Name}}</td> 

を働きました。ここでは、条件がtrueの場合にのみng-repeatの最初の要素のCssクラスを設定します。それ以外の場合は、 'いいえ' Cssクラスが適用されます。

上記の例では、「evaluationRow」は適用するCssクラスの名前であり、その後に条件が続きます。

関連する問題