You can do this by creating a second array of main categories. Using ng-repeat-start and ng-repeat-end, you create a basic structure (h1 + ul). In ul, the second repeater of categories filtered by the main category displays list items ( fiddle ):
<div ng-app ng-controller="MyCtrl"> <h1 ng-repeat-start="mainCategory in mainCategories | orderBy">{{mainCategory}}</h1> <ul ng-repeat-end> <li ng-repeat="category in categories | orderBy:'name' | filter:{ 'main_category': mainCategory}">{{category.name}}</li> </ul> </div> function MyCtrl($scope) { var categories = [{ name: 'somethingA2', main_category: 'A' }, { name: 'somethingB1', main_category: 'B' }, { name: 'somethingB2', main_category: 'B' }, { name: 'somethingA3', main_category: 'A' }, { name: 'somethingB3', main_category: 'B' }, { name: 'somethingA1', main_category: 'A' }]; $scope.categories = categories; /** main categories - reduce the categories array to a dictionary object, and get the keys of the dictionary to get the unique main category names **/ $scope.mainCategories = Object.keys(categories.reduce(function (main, category) { main[category['main_category']] = ''; return main; }, {})); }
source share