I am new to Angular.js and have some problems sorting my array and working on this sorted data.
I have a list with items and want to sort it by "Store.storeName", which still works. But after sorting the data, my delete function no longer works. I think this is because after sorting, the $ index is incorrect, and therefore the invalid data is deleted.
How can i solve this? Ordering data in an area, not in a view? How to do it?
Here is the code:
In view:
<tr ng-repeat="item in items | orderBy:'Store.storeName'"> <td><input class="toggle" type="checkbox" ng-model="item.Completed"></td> <td>{{item.Name}}</td> <td>{{item.Quantity}} Stk.</td> <td>{{item.Price || 0 | number:2}} €</td> <td>{{item.Quantity*item.Price|| 0 | number:2}} €</td> <td>{{item.Store.storeName}}</td> <td><a><img src="img/delete.png" ng-click="removeItem($index)">{{$index}}</a></td> </tr>
And in my controller, I have this delete function, which should delete certain data:
$scope.removeItem = function(index){ $scope.items.splice(index,1); }
This works well before ordering in view. If something important is missing, let me now.
Thank!
sorting angularjs indexing angularjs-orderby
FuzzBuzz Apr 20 '13 at 9:32 2013-04-20 09:32
source share