i_ll_be_back
i_ll_be_back

Reputation: 317

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?

Upvotes: 0

Views: 622

Answers (1)

victor175
victor175

Reputation: 624

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+.

Upvotes: 2

Related Questions