角JS - NG-重复和循环条件 [英] Angular JS - ng-repeat and loop conditions

查看:138
本文介绍了角JS - NG-重复和循环条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我这片code的:

Hey i have this piece of code:

<div ng-repeat="i in values">
{{i}}
</div>

它的工作原理,但我想提出附带条件的循环内是这样的:

It works but i would like to put extra conditions inside the loop something like:

<div ng-repeat="i in values">
{{i}}
if(i !== 0){
<div></div>
}
</div>

我怎样才能做到这一点?

How can i achieve this?

推荐答案

使用 NG-如果(或 NG-节目

<div ng-repeat="i in values">
   <div ng-if="i !== 0"></div>
</div>

附属的元素,这将决定是否显示与否。

Attached to the element, this will decide whether to display it or not.

有关文档NG-如果可以在这里找到

不过,如果你只想做一些事情,如果你是循环的第一个或最后一个项目,你可以使用 $第一个 $最后 NG-重复为好。这些是NG-重复记录 。并且可以使用这样的:

However, if you want to only do something if you are looping the first or last item, you can use $first and $last properties of ng-repeat as well. These are documented with ng-repeat. And can be used like this:

<div ng-repeat="i in values">
   <div ng-if="$first"></div>
</div>

这篇关于角JS - NG-重复和循环条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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