How to separate groups in ng-repeat

angularjs

Solution

You will want to create a function in your scope.

$scope.currentRole = 'something';
$scope.CreateHeader = function(role) {
      showHeader = (role!=$scope.currentRole); 
       $scope.currentRole = role;
      return showHeader;
}

And then in your HTML:

<div ng-app ng-controller="Main">
   <div ng-repeat="item in items | orderBy:'role'">
       <div ng-show="CreateHeader(item.role)">
       something here for the header
      </div>
        {{item.role}} - {{item.name}}

   </div>
</div>

Problem

I have items I want to show, normally by using ng-repeat. I want to show the in some order (easy), but whenever the ordered attribute changes, I want some HTML in-between. Example: (Fiddle): ``` <div ng-app ng-controller="Main"> <div ng-repeat="item in items | orderBy:'role'"> {{item.role}} - {{item.name}} </div> </div> function Main($scope){ $scope.items = [{name: 'First', role: 1}, {name: 'Second', role:2}, {name: 'Third', role: 1}, {name: 'Fourth', role: 2}]; } ``` I want it to print: 1 - First 1 - Third (some separator kode) 2 - Second 2 - Fourth

Original source

Related problems