I have an array of objects called $scope.segments like this:
[
{
"_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."
}
]
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:
<ul ng-repeat="segment in segments | orderBy: 'sequence'">
<li>{{ segment.sequence }}</li>
</u>
However, I need the orderBy filter to work in a controller. I'm doing this:
$scope.test = $filter('orderBy')($scope.segments, 'sequence');
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 ([]) shows. I imagine the $filter is not working in the controller.
Any ideas on how to solve this? Thanks!
$scope.segmentsis not empty when you print it, becauseng-repeatlistens onsegmentschange