I am trying to arrange an array of objects using the comparator function, but it seems that the comparator function is completely ignored (see the angular documentation).
I am using angularJS 1.5.6.
Here is the JSFiddle
Html:
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.6/angular.min.js"> </script> <body ng-app="app" ng-controller="ctrl"> {{msg}} </body>
JavaScript:
angular.module("app", []) .factory('f1', function($filter) { var f1 = {}; function comparator(a,b) { console.log(a,b); return a.id - b.id; } function getter(x) { return x; } f1.testOrderBy = function() { return $filter('orderBy')( [ {id:3}, {id:1}, {id:2} ], getter, false, comparator ) .map(function(x) { return x.id; }) }; return f1; }) .controller("ctrl", function($scope, f1) { $scope.msg = f1.testOrderBy(); })
My question is : Why is comparator ignored? (This can be seen since the console.log() call is never executed). Is this a corner mistake?
Because of this, I canβt even order an array of objects using a specialized comparator.
Thanks!
source share