This is my code
<a href="" ng-click="predicate = 'productname'; reverse=false">Productname</a>
<a href="" ng-click="predicate = 'productprice'; reverse=false">Productprice</a>
Iteration
<div ng-repeat="sale in sales | orderBy:customSort">
Customsort function
$scope.customSort = function(sale) {
};
Currently in the customSort function I get all the sale data but I also want to pass the predicate value to the function so that it can sort accordingly(sort by name if name is clicked, sort by price if price predicate is clicked.)
How can I pass the predicate value to the customSort function?Can any one please help me with this? Thanks.
You could call your custom sort with the predicate and return a closure being your original function, now your function has access to predicate:
<div ng-repeat="sale in sales | orderBy:customSort(predicate)">
$scope.customSort = function(predicate) {
return function(sale) {
};
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With