Print an array in Reverse order using AngularJS - ng-repeat | orderBy

A number of items can be printed in HTML as per the iteration counts using “ng-repeat” in AngularJS. The iteration count is the size of the array or object. The item can be printed in the reverse order using “orderBy”

Print in Reverse Order - Demo

Print values in reverse order in AngularJS using ng-regeat | orderBy
Print Array Numbers with out orderBy
  • {{todo}}

  • Print Array Numbers in reverse order using orderBy
  • {{todo}}

  • Print in Reverse Order - Example
    <html>
     
    <head>
    	<title>Print values in reverse order in AngularJS using ng-regeat | orderBy </title>
    	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>
     
    <body>
    	<div ng-app="myApp" ng-controller="myController">
    	  <div><strong>Print Array Numbers with out orderBy</strong></div>
    		<li ng-repeat="todo in input">
    			<span>{{todo}}</span>
    		</li>
    		<br/>
    		<div><strong>Print Array Numbers in reverse order using orderBy</strong></div>
    		<li ng-repeat="todo in input | orderBy:'-'">
    			<span>{{todo}}</span>
    		</li>
    	</div>
     
    	<script>
             var myApp = angular.module("myApp", []);
             myApp.controller('myController', function($scope) {
                $scope.input = [];
                for (var i=0; i<5; i++) {
                    $scope.input.push(i);
                }
             });
        </script>
    </body>
     
    </html>
    Category: