Sorting Ordered List element in AngularJS

Last Reply 6 months ago By dharmendr

Posted 6 months ago

How to Sort ordered list in asc or desc in angularjs

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