i_ll_be_back i_ll_be_back - 1 month ago 19
AngularJS Question

Sort list by property name AngularJS

I have a complex object that looks like:

{
'street35':[
{'address154': 'name14'},
{'address244': 'name2'}
],
'street2':[
{'address15': 'name1'},
{'address234': 'name2'}
]
}


I'm binding it to the html using the (value, key) in object attribute that angular.js provides. I want to order by the value in this case by the street name. Any suggestions?

Answer

You can try this code:

JS:

   $scope.streetsObject = {
      'street35':[
          {'address154': 'name14'},
          {'address244': 'name2'}
      ],
      'street2':[
          {'address15': 'name1'},
          {'address234': 'name2'}
      ]
   }

HTML:

<div ng-repeat="street in streetsObject | orderBy">
    <span ng-repeat"name in street">
    </span>
</div>

The code supposes that you are using angular 1.3.0+.