title: Angular template: Loop over object, sort by values
body: <p>I have a javascript object that I want to loop over in angular. The keys in the object are names and the value is a rank. I want to sort the elements by the rank. I tried this which didn't work:</p>
  
  <pre><code>ng-repeat="(name, rank) in topCategories | orderBy: '-rank'"
  </code></pre>
  
  <p>I also tried without the single quotes around the word "rank".
  The result is that the elements are looped over but not sorted. No error is logged. Is it possible to sort when iterating over objects?</p>
  
  <p>Example data source:</p>
  
  <pre><code>{
      foo: 5,
      bar: 7,
      baz: 42
  }
  </code></pre>
  
  <p><strong>Edit</strong> After inspecting the source code it is easy to see that the <code>orderBy</code> filter simply just returns at once if the supplied argument is an object and not an array. <a href="https://github.com/angular/angular.js/blob/master/src/ng/filter/orderBy.js#L68" rel="nofollow">https://github.com/angular/angular.js/blob/master/src/ng/filter/orderBy.js#L68</a></p>