Atousa Darabi
Atousa Darabi

Reputation: 937

How makes last-child in ng-repeat in AngularJs hidden?

I use ng-repeat in my code.

<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>

How can I hide the last hyphen? Is there a way to hide the last item in ng-repeat?

Upvotes: 1

Views: 31

Answers (2)

georgeawg
georgeawg

Reputation: 48968

Use the ng-hide directive with the $last special property:

<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>

For more information, see

Upvotes: 1

Atousa Darabi
Atousa Darabi

Reputation: 937

$last shows the last item in 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>

Upvotes: 1

Related Questions