<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="namesCtrl"> <p>Looping with objects:</p> <ul> <li ng-repeat="x in names | orderBy:'country'"> {{ x.name + ', ' + x.country }} </li> </ul> </div> <script> angular.module('myApp', []).controller('namesCtrl', function($scope) { $scope.names = [ {name:'New Delhi',country:'India'}, {name:'toronto',country:'Canada'}, {name:'Margareth',country:'England'}, {name:'Hege',country:'Norway'}, {name:'Joe',country:'Denmark'}, {name:'Gustav',country:'Sweden'}, {name:'Birgit',country:'Denmark'}, {name:'Mary',country:'England'}, {name:'Kai',country:'Norway'} ]; }); </script> </body> </html>
Output:
Looping with objects:
- toronto, Canada
- Joe, Denmark
- Birgit, Denmark
- Margareth, England
- Mary, England
- New Delhi, India
- Hege, Norway
- Kai, Norway
- Gustav, Sweden
ng-repeat with orderBy example in Angular JS
Working Code Asked question September 21, 2023