Pass extra parameters to custom sort function in AngularJS

angularjs, javascript, sorting

Solution

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) {


    };
};

Problem

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.

Original source