I have received data from an API in the form of an array with objects structured like so:
[
{"desc":"a", "menu": 1},{"desc":"b", "menu": 2},{"desc":"c", "menu": 1},
{"desc":"d", "menu": 3},{"desc":"e", "menu": 3},{"desc":"f", "menu": 2},
{"desc":"g", "menu": 1},{"desc":"g", "menu": 1},{"desc":"g", "menu": 4},
{"desc":"g", "menu": 4},{"desc":"g", "menu": 4}
]
I want to display these objects using *ngFor, grouped by their "menu" property, and with a corresponding label for each group as follows:
Menu 1
{all objects with menu 1}
Menu 2
{all objects with menu 2}
Menu 3
{all objects with menu 3}
To achieve this, I plan to use *ngFor and set up logic to create labels for each menu group. Here is a rough outline of how I would approach it:
*ngFor="let object of objects; let currentMenu = 0"
if currentMenu !== object.menu
currentMenu === object.menu
CREATE LABEL
If you have any suggestions on how to implement this effectively in actual code, please share them!