I have an array of objects of the form
widgets = [
{
id: 1,
created: '12/1/2017',
weight: 2
},
{
id: 2,
created: '12/1/2017',
weight: 1
},
{
id: 3,
created: '12/2/2017',
weight: 2
},
{
id: 4,
created: '12/3/2017',
weight: 2
}
]
Currently to get the organization I'm after I 'massage' the data so that I can iterate through it with *ngFor
loops to produce panels which look something like
|12/1/2017 |
| ID | Weight |
| 1 | 2 |
| 2 | 1 |
|12/2/2017 |
| ID | Weight |
| 3 | 2 |
|13/3/2017 |
| ID | Weight |
| 4 | 2 |
So after the 'massaging' the above widgets
array looks like the below array
widgets = [
{
date: '12/1/2017',
recs: [
{
id: 1,
created: '12/1/2017',
weight: 2
},
{
id: 2,
created: '12/1/2017',
weight: 1
}
]
},
{
date: '12/2/2017',
recs: [
{
id: 3,
created: '12/2/2017',
weight: 2
}
]
},
{
date: '12/3/2017',
recs: [
{
id: 4,
created: '12/3/2017',
weight: 2
}
]
}
]
Is there some templating trick I can do with Angular4 to get the panel grouping I'm after without having to reorganize my original array structure?
Perhaps a directive I can place on an element in my template to achieve this?