角JS:如何找到一个和最后一个元素NG重复,并添加特殊类呢? [英] Angular Js : How to find first and last element in ng-repeat and add special class to them?
本文介绍了角JS:如何找到一个和最后一个元素NG重复,并添加特殊类呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我改变了下面采用了棱角分明的js
I changed the following using angular js
<section id="social">
<h2 class="line">Social Profiles</h2>
<a href="#" class="first"><i class="icon-facebook"></i></a>
<a href="#"><i class="icon-twitter"></i></a>
<a href="#"><i class="icon-linkedin"></i></a>
<a href="#"><i class="icon-google-plus"></i></a>
<a href="#" class="last"><i class="icon-rss"></i></a>
<div class="clear"></div>
</section>
要这个
<section id="social">
<h2 class="line">Social Profiles</h2>
<a ng-repeat="sMedia in socialMedia" ng-if="$first" href="#" >
<i class="{{sMedia.icon}}"></i>
</a>
<div class="clear"></div>
</section>
似乎一切都只是我精无法找到一个方法来添加类=第一
中的第一个元素和类=最后
在 NG-重复
。
Everything seems fine except I could not find a way to add class="first"
in the first element and class="last"
in the last element of ng-repeat
.
推荐答案
只需使用$第一和最后一个$ NG与一流组合:
Just use $first and $last combined with ng-class:
<a ng-repeat="sMedia in socialMedia" ng-class="{'first': $first, 'last': $last}" href="#" >
在这里看到他们是如何工作的: https://docs.angularjs.org/api/纳克/指令/ ngRepeat
这篇关于角JS:如何找到一个和最后一个元素NG重复,并添加特殊类呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文