Skip to content

Instantly share code, notes, and snippets.

@DomiR
Created May 14, 2014 07:26
Show Gist options
  • Save DomiR/77c3dc80380489f45d15 to your computer and use it in GitHub Desktop.
Save DomiR/77c3dc80380489f45d15 to your computer and use it in GitHub Desktop.
Order by object field.
yourApp.filter('orderObjectBy', function() {
return function(items, field, reverse) {
var filtered = [];
angular.forEach(items, function(item) {
filtered.push(item);
});
filtered.sort(function (a, b) {
return (a[field] > b[field] ? 1 : -1);
});
if(reverse) filtered.reverse();
return filtered;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment