I want to do an ng-repeat over an array, skipping certain properties when they are duplicates of a previous iteration.
Model ("events" array)
[
{
"id": "event1",
"date": "June 1st"
},
{
"id": "event2",
"date": "June 2nd"
},
{
"id": "event3",
"date": "June 2nd"
},
{
"id": "event4",
"date": "June 3rd"
}
]
As you can see the date is duplicated for event2
and event3
...
HTML
<div ng-repeat="event in events">
<h2>{{event.date}}</h2>
<p>{{event.id}}</p>
<hr>
</div>
So the desired result is:
June 1st
event1
June 2nd
event2
event3
June 3rd
event4
My guess is it is something like:
<div ng-repeat="event in events">
<h2 ng-if="<!--expression here-->">{{event.date}}</h2>
<p>{{event.id}}</p>
<hr>
</div>
Would it be a function in my controller attached to a variable called in the ng-if attribute?
And primarily, how would I form that expression to do what I want in this case?
Note: It is ONLY the rendering of the date variable I want to avoid, not the entire ng-repeat element.
Any help, or alternative suggestions would be appreciated.