I have some JSON in the below format. I need to convert it into a menu with a sub menu when sub-menu_location is not equal to null, as below 
{
"data": [
{
"menu_name": "Primary Operations",
"enabled": true,
"sub-menu_location": null
},
{
"menu_name": "Curated Games",
"enabled": false,
"sub-menu_location": null
},
{
"menu_name": "Cricket",
"enabled": false,
"sub-menu_location": "outdoor"
},
{
"menu_name": "football",
"enabled": false,
"sub-menu_location": "outdoor"
},
{
"menu_name": "Hockey",
"enabled": false,
"sub-menu_location": "outdoor"
}
]
}
A couple of things to note:
If you store the data object as a property in your component, the following template should give you something to start with:
<li>
<a class="dropdown-toggle" data-toggle="dropdown">Menu<b class="caret"></b></a>
<ul class="dropdown-menu multi-level">
<li *ngFor="let menuItem of data" class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{menuItem.menu_name}}</a>
<ul *ngIf="menuItem.sub-menu_location" class="dropdown-menu">
<li><a href="#">{{menuItem.sub-menu_location}}</a></li>
</ul>
</li>
</ul>
</li>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With