0

I am trying to use orderBy in ng-repeat using angular js.but it fail to sort my list .here is my code ?

how to sort my code

https://jsfiddle.net/7MhLd/1921/

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
    $scope.lines = {
        "a" : {name:"bb"},
        "aa": {name: 'aa'},
        "zz": {name:"zz"},
        "oo": {name: 'oo'}, 
        "kk": {name:"k"},
        "j" : {name: "a"},
        "n" : {name:"n"},
        "c" : {name: "c"}
   }
} 
Smit Patel
  • 2,992
  • 1
  • 26
  • 44
user944513
  • 12,247
  • 49
  • 168
  • 318

1 Answers1

0

You will have to turn your object into array in order to get it to work

<div ng-controller="MyCtrl">
  <div ng-repeat="line in lines | orderBy:'name'">
    <div class="preview">{{line.name}} {{$index}}</div>
  </div>
</div>

and controller

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
    $scope.lines = [
       {name:"bb"},
    {name: 'aa'},
    {name:"zz"},
    {name: 'oo'}, 
    {name:"k"},
    {name: "a"},
    {name:"n"},
    {name: "c"}
];
}
Max Kroshka
  • 457
  • 2
  • 5