Aravinth
Aravinth

Reputation: 407

how to hide one row in ng-repeat that doesn't affect $index value

This is my ng-repeat

   <tr ng-repeat="userList in userLists" ng-if="userLists.role!='admin'">
      <td data-th="S.no">{{$index+1}}</td>
      <td data-th="Role">{{userList.role}}</td>
      <td data-th="Email">{{userList.email}}</td>
      <td data-th="Mobile">{{userList.mobile}}</td>
      <td data-th="Downloads">0</td>
   </tr>

i want to hide admin from the user list. but the problem is, that also hide that $index value.

enter image description here

then how to hide that properly...

Upvotes: 0

Views: 1059

Answers (1)

Hmahwish
Hmahwish

Reputation: 2232

If users with 'admin' role should only be displayed

 <tr ng-repeat="userList in userLists | filter:{role:'admin'}" >
  <td data-th="S.no">{{$index+1}}</td>
  <td data-th="Role">{{userList.role}}</td>
  <td data-th="Email">{{userList.email}}</td>
  <td data-th="Mobile">{{userList.mobile}}</td>
  <td data-th="Downloads">0</td>
 </tr>

If users with 'user' role should only be displayed

<tr ng-repeat="userList in userLists | filter:{role:'user'}" >
  <td data-th="S.no">{{$index+1}}</td>
  <td data-th="Role">{{userList.role}}</td>
  <td data-th="Email">{{userList.email}}</td>
  <td data-th="Mobile">{{userList.mobile}}</td>
  <td data-th="Downloads">0</td>
 </tr>

Upvotes: 3

Related Questions