angularjs - :first-child with ng-repeat

标签 angularjs css angularjs-ng-repeat css-selectors

我有一个 ng-repeat,只想将样式应用到第一个 div,在 ng-repeat 中具有类 type

<div class="my-list" ng-repeat="item in list">
  <div class="type">
    <span>{{item.label}}</span>
  </div>
  <div class="check">
    <span>{{item.ischecked}}</span>
  </div>
</div>

我尝试了以下方法,但它将 CSS 应用于所有 divtype

.my-list .type:first-child

最佳答案

您可以使用 $first,它表示 ng-repeat 中的第一次迭代。

<div class="my-list" ng-repeat="item in list">
  <div class="type" ng-class="{myClass:$first}">
    <span>{{item.label}}</span>
  </div>
  <div class="check">
    <span>{{item.ischecked}}</span>
  </div>
</div>

关于angularjs - :first-child with ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25630079/

相关文章:

javascript - 为表中的每一行循环两个数组

javascript - 刷新时重置值?

javascript - 使用 angularJs 重定向到其他项目

angularjs - $stateProvider 没有按预期加载页面

html - 由图像组成的全高侧边导航栏 - 怎么做?

html - Bootsnipp 单选按钮

javascript - 显示 ng-repeat 中的嵌套对象键和值

javascript - 如何在 AngularJS 中使用 ng-repeat 插入 html 代码?

javascript - 带有 "restrict"和不带 "restrict"的 Angular Directive(指令)

html - 无法将 img 与背景图像一起使用 : url()