Example of sorting in AngularJS

Rajnilari2015
Posted by Rajnilari2015 under AngularJS 1x category on | Points: 40 | Views : 1398
<!DOCTYPE html>

<html>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<body>



<div ng-app="myApp" ng-controller="orderCtrl">


<ul>

<li ng-repeat="x in collection | orderBy : 'X1'">

{{x.X1 }}

</li>

</ul>
</div>
<script>

var app = angular.module('myApp', []);

app.controller('orderCtrl', function($scope) {



$scope.collection = [

{ X1: 'Dhoni', X2: 'Simla' },

{ X1: 'Kohli', X2: 'Manali'},

{ X1: 'Virat', X2: 'Rajasthan' },

{ X1: 'Yuvraj', X2: 'Kerala' },

{ X1: 'Singh', X2: 'Mysore' },

{ X1: 'Murali', X2: 'OOTY' },

{ X1: 'Vijay', X2: 'Goa' }

];

});

</script>



</body>

</html>


Output 
----------

Dhoni

Kohli

Murali

Singh

Vijay

Virat

Yuvraj

Comments or Responses

Posted by: Nagamohan on: 3/14/2017 Level:Starter | Status: [Member] | Points: 10
Dear Rajnilari,

Thanks for sharing your knowledge, but am having small question, in the above code you have explained how to sort values , you have explained sorting x1 values, how to sort both x1 and x2 values.
Posted by: Nagamohan on: 3/14/2017 Level:Starter | Status: [Member] | Points: 10
Dear Rajnilari

Thanks for sharing,Can you explain how to sort both x1 and x2 values
Posted by: Rajnilari2015 on: 3/14/2017 Level:Platinum | Status: [Member] [Microsoft_MVP] [MVP] | Points: 10
orderBy : ['X1','X2']

Login to post response