A dynamic tree view structure based on JSON data in angular6
Need to create a dynamic tree view structure with dynamic data (data/structure may get changed)
Angular6, JSON
- assets/menu-data.json //data in JSON
- service/get-data.service.ts //service to call data
- service/data.ts //Interface file
- components/dashboard //Parent component
- components/tree-view //Child component
- Have your JSON data ready.
- Create a service to fetch the data. Need to import {Observable} from 'rxjs'
- Create a component "dashboard" and subscribe data from service (step 2)
- Pass the public variable "getTreeViewData" from Parent component (dashboard) > child component (tree-view) <app-tree-view [parentData]='getTreeViewData'>
- Apply recursive method to inject in itself so that if any sub-item has any further category then the loop can be iterated.
- Call the dashboard component in you main app i.e. app-component.