Sorting Ordered List element in AngularJS

Last Reply 27 days ago By dharmendr

Posted 27 days ago

How to Sort ordered list in asc or desc in angularjs

You are viewing reply posted by: dharmendr 27 days ago.
Posted 27 days 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>