Reverse $ index when listing items in reverse order

I messed up this post on how to reverse display an array, which works great when I try to do it. angular ng-repeat backwards

However ... then the itmes, I am listing editable, and when I change the array, the $ index does not change, so when I edit one of the listed items, the edit occurs on another item that contains the correct index.

So how can I check that my $ index is also canceled?

So the code looks like this:

<form action="" method="post" autocomplete="off" ng-controller="itemCtrl">
 <input type="text" name="createitem" ng-model="item" />
 <button ng-click="addItem(item)">Add item</button>
       <li ng-repeat="item in items | reverse">

Run codeHide result

var itemApp = angular.module('itemApp', []);

itemApp.filter('reverse', function() {
 return function(items) {
  return items.slice().reverse();

itemApp.controller('itemCtrl', function ($scope) {

            $scope.items = [];

            $scope.addItem = function(item){
                    title: item


Run codeHide result


source to share

1 answer

This is what I am using. You just need to subtract the length of the array using the current one $index


{{myArray.length - $index}}




All Articles