不同类为NG-重复的最后一个元素 [英] Different class for the last element in ng-repeat

查看:156
本文介绍了不同类为NG-重复的最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用NG重复这样的事情的清单。

I am creating a list using ng-repeat something like this

  <div ng-repeat="file in files">
   {{file.name}}
   </div>

但对于最后一个元素孤独,我想有一个类(&LT; D​​IV CLASS =最后一个&GT;测试&LT; / DIV&GT; ),包括它。我如何才能做到这一点使用NG-重复?

But for the last element alone I would like to have a class (<div class="last">test</div>) included to it. how can i achieve this using ng-repeat?

推荐答案

您可以使用在 NG-重复 $最后变量$ C>指令。看看 DOC

You can use $last variable within ng-repeat directive. Take a look at doc.

您可以做到这一点是这样的:

You can do it like this:

 <div ng-repeat="file in files" ng-class="computeCssClass($last)">
 {{file.name}}
 </div>

其中, computeCssClass 控制器这需要唯一的参数并返回的功能'最后'

Where computeCssClass is function of controller which takes sole argument and returns 'last' or null.

或者

  <div ng-repeat="file in files" ng-class="{'last':$last}">
  {{file.name}}
  </div>

这篇关于不同类为NG-重复的最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆