title: Sorting an array of objects based on a property in an Angular controller using $filter
body: <p>I have an array of objects called <code>$scope.segments</code> like this:</p>
  
  <pre><code>[
    {
      "_id": "55d1167655745c8d3679cdb5",
      "job_id": "55d0a6feab0332116d74b253",
      "status": "available",
      "sequence": 1,
      "body_original": "Such a fork",
      "__v": 0,
      "body_translated": "Tal bifurcación"
    },
    {
      "_id": "55d1167655745c8d3679cdb4",
      "job_id": "55d0a6feab0332116d74b253",
      "status": "available",
      "sequence": 0,
      "body_original": "So this is it.",
      "__v": 0,
      "body_translated": "Así que esto es."
    }
  ]
  </code></pre>
  
  <p>I need to order this by array by sequence. So, I need the sequence 0 to appear first, the sequence 1 to appear next, and so on. In a view, I'm doing this and it works: </p>
  
  <pre><code>&lt;ul ng-repeat="segment in segments | orderBy: 'sequence'"&gt;
      &lt;li&gt;{{ segment.sequence }}&lt;/li&gt;
  &lt;/u&gt;
  </code></pre>
  
  <p>However, I need the orderBy filter to work in a controller. I'm doing this: </p>
  
  <pre><code>$scope.test = $filter('orderBy')($scope.segments, 'sequence');
  </code></pre>
  
  <p>Where, $scope.test should be my ordered array of objects based on the the sequence property. However, when I do console.log('$scope.test') an empty array (<code>[]</code>) shows. I imagine the $filter is not working in the controller.</p>
  
  <p>Any ideas on how to solve this? Thanks!</p>