d_z90 d_z90 - 5 months ago 29
AngularJS Question

ng-repeat orderBy issue

through

ng-repeat
I want to plot videos in a defined order according to the
id
number (from 1 to 5).

<div ng-app="myApp" ng-controller="Ctrl">
<div ng-repeat="vidObj in videoObjects | orderBy: 'id'">
<span>{{vidObj.id}}</span>
</div>
</div>


I try to apply the filter
orderBy
, but apparently is not working properly. Do you have an idea of what I am doing wrong? This is a JSfiddle with the complete code.

Thanks in advance for your replies!

EDIT: Thank you for your replies, but the
json
file can not change.

Answer

The Javascript :

angular.module('myApp', [])
    .controller('Ctrl', function($scope) {
        $scope.videoObjects = {
        "Frank": {
          "id": 1
        },
        "Gerard": {
          "id": 2
        },
        "Rein": {
          "id": 3
        },
        "Ida": {
          "id": 4
        },
        "Ellen": {
          "id": 5
        }
      };

 $scope.arr = Object.keys($scope.videoObjects).map(function(k) { return $scope.videoObjects[k] });
console.log($scope.arr);

    });

and the HTML

<div ng-app="myApp" ng-controller="Ctrl">
    <div ng-repeat="vidObj in arr | orderBy: 'id'">
        <span>{{vidObj.id}}</span>  
    </div>
</div>

I updated your fiddle with this code.. It is working well.

Here is the link http://jsfiddle.net/tirthrajbarot/fc16op6u/39/