I need to create grouped dropdown select using Angular. In my case group is make
.
const cars = [{
make: "audi",
model: "r8",
year: "2012"
},
{
make: "audi",
model: "rs5",
year: "2013"
},
{
make: "ford",
model: "mustang",
year: "2012"
},
{
make: "ford",
model: "fusion",
year: "2015"
},
{
make: "kia",
model: "optima",
year: "2012"
}
];
So the output would be dropdown select with options:
audi
- r8
- rs5
ford
- mustang
- fusion
kia
- optima
And I wondering whether should I transform this object before? For example similar to this solution: https://medium.com/@edisondevadoss/javascript-group-an-array-of-objects-by-key-afc85c35d07e
Or maybe there is another better way. I found this https://stackblitz.com/edit/angular-optgroup. But the structure of object is kinda different.