Having an array of multiple objects:
{
"option_12": {
"id": "0",
"name": "6 x 330ml",
"price": "0.00"
},
"option_14": {
"id": 1,
"name": "12 x 330ml",
"price": "2.00"
},
"option_17": {
"id": 1,
"name": "15 x 330ml",
"price": "4.00"
},
"option_10": {
"id": 1,
"name": "30 x 330ml",
"price": "1.00"
}
}
Using AngularJS Filter orderBy to sort the objects based on price value. Therefore, option_12 should be first and option_10 should be second.
In controller:
$scope.pOptions = $filter('orderBy')($scope.pOptions, 'price');
In the view where select options are populated using ng-options:
<select ng-model="SelectedPOption" ng-options="option.name for option in pOptions|orderBy:'price'"></select>
However, these attempts have not produced any result. https://docs.angularjs.org/api/ng/filter/orderBy