如何隐藏AngularJs中ng-repeat中的最后一个孩子?

时间:2018-12-30 08:44:41

标签: angularjs angularjs-ng-repeat

我在代码中使用ng-repeat。

<span ng-repeat="provide in user.profiles">
  <span ng-switch on="provide.provider">
     <span ng-switch-when="google" class="color-google">GOOGLE</span>
     <span ng-switch-when="yahoo" class="color-tinet">YAHOO</span>
  </span>
  <span> - </span>
</span>

如何隐藏最后一个连字符? 有没有办法隐藏ng-repeat中的最后一个项目?

2 个答案:

答案 0 :(得分:1)

$ last显示ng-repeat中的最后一项。

<span ng-repeat="provide in user.profiles">
  <span ng-switch on="provide.provider">
     <span ng-switch-when="google" class="color-google">GOOGLE</span>
     <span ng-switch-when="yahoo" class="color-tinet">YAHOO</span>
  </span>
  <span ng-if="!$last"> - </span>
</span>

答案 1 :(得分:1)

ng-hide指令与$last特殊属性一起使用:

<span ng-repeat="provide in user.profiles">
  <span ng-switch on="provide.provider">
     <span ng-switch-when="google" class="color-google">GOOGLE</span>
     <span ng-switch-when="yahoo" class="color-tinet">YAHOO</span>
  </span>
  <span ng-hide="$last"> - </span>
</span>

有关更多信息,请参见