Searching for a way to create a grouped dropdown select using Angular? In this case, the group is based on the make
property.
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"
}
];
Expecting the dropdown select options to be grouped as follows:
audi
- r8
- rs5
ford
- mustang
- fusion
kia
- optima
Contemplating whether to transform the object before or explore other alternatives. Considered this approach: https://medium.com/@edisondevadoss/javascript-group-an-array-of-objects-by-key-afc85c35d07e
Alternatively, stumbled upon this solution: https://stackblitz.com/edit/angular-optgroup. However, note that the object structure differs.