Sorting Ordered List element in AngularJS

Last Reply 5 months ago By dharmendr

Posted 5 months ago

How to Sort ordered list in asc or desc in angularjs

Posted 5 months ago

Hi rani,

You can use JavaScript Array sort and reverse method.

Check this example.


<html xmlns="">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', [])
        app.controller('MyController', function ($scope) {
            $scope.Fruits = ['Mango', 'Apple', 'Banana', 'Orange', 'Guava'];
            $scope.SortFruits = function (order) {
                if (order == 'asc') {
                } else if (order == 'desc') {
    <div ng-app="MyApp" ng-controller="MyController">
        <input type="button" value="Ascending Fruits" ng-click="SortFruits('asc')" />
        <input type="button" value="Descending Fruits" ng-click="SortFruits('desc')" /><br />
        <ol><li ng-repeat="fruit in Fruits">{{fruit}}</li></ol>