javascript - AngularJS:ng-show 显示 ng-repeat 中 $index 的最高值

标签 javascript angularjs

我有一个电子邮件地址和地址的输入表单。

用户可以通过单击输入字段右侧的 + 符号动态添加最多 3 个电子邮件和地址行。

当我 ng-repeat 输入字段时 + 也会为每个输入字段重复。 如何仅针对 $index 的值最大的最后一个输入字段显示 +。 This is my actual form![][1]

最佳答案

您可以改为使用 ng-repeat$last 特殊属性。它是为最后一项设置的 bool 值属性(item 这里表示 child scope 由 ng-repeat 创建,而不是那个特定的值ng-repeat 中的迭代)。像这样的东西:

  ... ng-show="$last"

 ... ng-if="$last"

See other special properties of ng-repeat

  • $index - number iterator offset of the repeated element (0..length-1)
  • $first - boolean true if the repeated element is first in the iterator.
  • $middle - boolean true if the repeated element is between the first and last in the iterator.
  • $last - boolean true if the repeated element is last in the iterator.
  • $even - boolean true if the iterator position $index is even (otherwise false).
  • $odd - boolean true if the iterator position $index is odd (otherwise false).

另请注意,如果您打算使用 ng-show(而不是 ng-if),您也可以使用 css 选择器伪类来实现它,例如 :last-child , :last-of-type基于上下文和 DOM 结构等。

关于javascript - AngularJS:ng-show 显示 ng-repeat 中 $index 的最高值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31033423/

相关文章:

javascript - Ionic + Angular ui-sref 不生成 href

javascript - 通过删除双引号在 html 中将 "&lt"显示为 <

javascript - 如何获取蓝色文本选择的大小?

javascript - 在 Angular 中,如何将指令的 Controller 共享给其子内容(当 transinclude 为 true 时)?

javascript - 如何使用 AngularJS 在单击正文内的任意位置时显示弹出窗口?

javascript - 使用 jshint 和 jenkins checkstyle-plugin 配置特定警告以报告错误

javascript - 如何在 ng-repeat 中将对象属性别名为变量

javascript - 如何在jquery中右键单击添加dbclick()

javascript - 我可以在同名对象内拥有属性(字段)和方法吗?

javascript - 推进器集成