AngularJS toArray Filter
HTML
<div ng-app>
<div ng-contoller="TestController">
</div>
</div>
JavaScript
// util - general purpose util filters.
angular.module("app",[])
/**
* Filter to take an object and convert it to an array. Intended for the
* case where you have an object that you want to use orderBy with. For
* example, given an object like:
*
* {
* "key1": { a: 0, b: 4 },
* "key2": { a: 1, b: 3 },
* "key3": { a: 2, b: 2 }
* }
*
* You could still use orderBy like:
*
* ng-repeat='item in items | toArray | orderBy:"a"'
*
* angular currently does not support orderBy over objects.
*/
.filter("toArray", function() {
return function(input) {
if(!input) return;
if (input instanceof Array) {
return input;
}
return $.map(input, function(val) {
return val;
});
};
}).controller('TestController', function($scope) {
$scope.data = "";
});