Sajith Sajith - 1 year ago 84
AngularJS Question

How to reverse an array in angular js without creating a filter

I am having an array in controller as follows

function FooController($scope) {
$scope.items = ["a","b","c"];

I used ng-repeat to show the data in

<div ng-app>
<div ng-controller="FooController">
<ul ng-repeat="item in items">

I got the result as a,b,c order. I want to show it in reverse order. that means c,b,a without changing its order in the controller or without creating a filter. How to do that?
Check this link

Answer Source

In order to avoid the writting of a custom filter, I suggest you to use this syntax :

  <ul ng-repeat="item in items |  orderBy:'-toString()'">

The documentation assume you sort an array of Objects but in your case there are just plain strings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download