When creating an application with Angular.js, I was using the $index variable inside an ng-repeat to track the index of the current item. The problem was that the moment I start combining this with an orderBy filter, the $index value was no longer correct.
I worked around the issue by passing the item itself around instead of the index. In my
function I used the indexOf
method of an array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.edit = function (movie) { | |
$scope.editable = { | |
index: $scope.movies.indexOf(movie), | |
movie: angular.copy(movie) | |
}; | |
}; |
Anyone with a better solution?