:first-child with ng-repeat [英] :first-child with ng-repeat
本文介绍了:first-child with ng-repeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 ng-repeat 并且只想将样式应用到第一个 div
和 ng-repeat 中的 type
类.
<div class="type"><span>{{item.label}}</span><div class="check"><span>{{item.ischecked}}</span>
我尝试了以下方法,但它将 CSS 应用于所有 divs
的 type
.my-list .type:first-child
解决方案
您可以使用 $first
,表示 ng-repeat
中的第一次迭代.>
<div class="type" ng-class="{myClass:$first}"><span>{{item.label}}</span><div class="check"><span>{{item.ischecked}}</span>