So I have an array that I'm using ng-repeat to render out but I want to reverse this list. Previously I have used a filter which i got from this answer: angular ng-repeat in reverse
But now I get an error: "TypeError: Object # has no method 'slice' at Scope." I'm not sure if this is because of a new version of AngularJS or I'm missing something.
This is my filter code:
.filter('reverse', function () {
return function(items) {
return items.slice().reverse();
};
This is the code from my view from inside the div:
data-ng-repeat='feed in feeds | reverse'
But ng-repeat is not the right thing to use when you have large datasets as it involves heavy DOM manipulations. And you should consider using ng-repeat with pagination. You can consider using transclusion inside a custom directive, to achieve the behavior you are looking for without using ng-repeat.
Definition and Usage The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.
reverse() is an inbuilt TypeScript function which is used to reverses the element of an array. Syntax: array. reverse();
a solution which doesn't sort the array, but only copies and reverses it:
ng-repeat="item in items | orderBy : '[]': true"
Please use directly Java-script slice function with reverse like this:
data-ng-repeat="item in items.slice().reverse()"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With