I want to display a list of records. The data is a list of objects, each object is like this:
{
date: "01/01/2001",
time: "04:28 AM",
message: "message strings here."
}
I want to display them in the way that grouped by date. Like this:
08/01/2005
04:28 AM message strings here.
04:20 AM message strings here.
02:12 AM message strings here.
07/05/2005
03:32 PM message strings here.
02:12 PM message strings here.
This is my code:
<div>{{date}}</div> <!--date is initialized in my angular controller to be the first date in the records.-->
<div ng-repeat="record in records">
<div ng-if="record.date != date" ng-model="date">{{record.date}}</div> <!--here I expect date would be updated to record.date.-->
<div>{{record.time}} {{record.message}}</div>
</div>
But I get result like this:
08/01/2005
04:28 AM message strings here.
04:20 AM message strings here.
02:12 AM message strings here.
07/05/2005
03:32 PM message strings here.
07/05/2005 //This is displayed, means the date is not updated when it reach the first 07/05/2005 above.
02:12 PM message strings here.
I searched online, a lot of model data binding is to bind model with <input>
. But I don't want input tag. And the ng-model in <div>
seems doesn't update the model to the text displayed in the <div>
. I wonder what's the proper way to achieve this.