GURURAJ DHARANI GURURAJ DHARANI - 4 months ago 9
Javascript Question

I was trying to print array indexes , but how do we do it in reverse order in angularjs

<tr ng-repeat="qualityalert in qualityalerts" current="$parent.start;$parent.start=$parent.start+(qualityalerts.length);">
<td class="v-middle">{{current + $index}}</td>
</tr>


Note: This is one which I was referring to, but I want array indexes in reverse order in angular js.

Answer
<div ng-app="myapp" ng-controller="AppController">
 <table class="friends">
  <tr>
   <th>Order</th><th>Name<th><th>Phone Number</th><th>Age</th>
  </tr>
    <tr ng-repeat="(k,friend) in friends| orderBy:'-' ">
    <td>{{friends.length - $index}}</td>
    <td>{{friend.name}}</td>
    <td>{{friend.phone}}</td>
    <td>{{friend.age}}</td>
  </tr>
 </table>
</div>


app=angular.module('myapp', [])
app.controller('AppController', ['$scope', function($scope) {
 $scope.friends = [
  {name: 'John',   phone: '555-1212',  age: 10},
  {name: 'Mary',   phone: '555-9876',  age: 19},
  {name: 'Mike',   phone: '555-4321',  age: 21},
  {name: 'Adam',   phone: '555-5678',  age: 35},
  {name: 'Julie',  phone: '555-8765',  age: 29}
 ];
}]);

Demo Link

check with this.I thing this will help you

Comments