Given a list of items displayed with ng-repeat I want to display extra stuff whenever a value in a column changes, eg:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.cards = [
{suit: 'Hearts', value: 7},
{suit: 'Clubs', value: 7},
{suit: 'Spades', value: 7},
{suit: 'Diamonds', value: 7},
{suit: 'Hearts', value: 8},
{suit: 'Clubs', value: 8},
{suit: 'Spades', value: 8},
{suit: 'Diamonds', value: 8},
{suit: 'Hearts', value: 9},
{suit: 'Clubs', value: 9},
{suit: 'Spades', value: 9},
{suit: 'Diamonds', value: 9} ];
$scope.myValueFunction = function(card) {
return [card.suit, card.value];
};
}
I need the following result:
The Clubs
7
8
9
The Diamonds
7
8
9
The Hearts
7
8
9
The Spades
7
8
9
I would prefer to have a HTML something like that:
<div ng-controller="MyCtrl">
<div ng-repeat="card in cards | orderBy:myValueFunction">
<div break-on-column="card.suit">The {{card.suit}}</div>
<div>{{card.value}}</div>
</div>
</div>
Of course, the real problem contains many columns (not just two), several break columns (eg: break-on-column="col1,col2,col3"), the break columns are not fixed (ie. the are chosen by the user at runtime).