How to sort the nested array below in ascending and descending order based on angular click()
function for address, price and time individually.
What I need is by default it must be sorted by price ascending order and on click()
other properties such as address, price and time should sort in ascending and descending order.
Any Help would me much appreciated.
Code:
var app = angular.module('aaa',[]); // snippet
app.controller('myCtrl', function($scope) {
$scope.myData = [{
lstjourney: {
0: {
lstit: {
0: {
address: 'mumbai',
price: 9255,
time: '10-nov-2018 08:54:19 am'
},
}
}
}
},
{
lstjourney: {
0: {
lstit: {
0: {
address: 'Vikroli',
price: 4556,
time: '04-nov-2018 08:54:19 am'
},
}
}
}
},
{
lstjourney: {
0: {
lstit: {
0: {
address: 'Hyderabad',
price: 5896,
time: '10-nov-2018 08:54:19 am'
}
}
}
}
}
];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script> <!-- snippet -->
<div ng-app="aaa" ng-controller="myCtrl">
<ul>
<li ng-click="SortFun('price')">price</li>
<li ng-click="SortFun('time')">time</li>
<li ng-click="SortFun('address')">address</li>
</ul>
<div ng-repeat="(names,itemR) in myData ">
<div ng-repeat="(name,item) in itemR.lstjourney ">
{{item.lstit[0].price}}---{{item.lstit[0].time}}-- {{item.lstit[0].address}}
</div>
</div>
</div>