ng-repeat 中最后一个元素的不同类 [英] Different class for the last element in ng-repeat
本文介绍了ng-repeat 中最后一个元素的不同类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用类似这样的 ng-repeat 创建一个列表
{{文档名称}}
但是对于最后一个元素,我希望包含一个类 (<div class="last">test</div>
).我如何使用 ng-repeat 实现这一目标?
解决方案
您可以在 ng-repeat
指令中使用 $last
变量.看看doc.
你可以这样做:
{{文档名称}}
其中 computeCssClass
是 controller
的函数,它接受唯一参数并返回 'last'
或 null
.
或
{{文档名称}}
I am creating a list using ng-repeat something like this
<div ng-repeat="file in files">
{{file.name}}
</div>
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?
解决方案
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>
Where computeCssClass
is function of controller
which takes sole argument and returns 'last'
or null
.
Or
<div ng-repeat="file in files" ng-class="{'last':$last}">
{{file.name}}
</div>
这篇关于ng-repeat 中最后一个元素的不同类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文