I am looking to utilize the functionality of a MenuComponent
located within a module named menu
. Specifically, I need to invoke the getMenu(path:string)
method from this component in the AppComponent
, which belongs to a different module.
Below is the code snippet for my MenuComponent
:
import { Component, OnInit } from '@angular/core';
import {
TreeComponent,
TreeNode,
} from 'angular-tree-component';
import { MenuService } from '../../menu.service';
@Component({
selector: 'menu',
templateUrl: './menu.component.html',
styleUrls: ['./menu.component.css']
})
export class MenuComponent {
constructor(private menuService: MenuService) { }
nodes:any;
getMenu(path:string): void {
this.menuService.getData(path).subscribe(data => {
// Extract data from JSON response.
let newValue = JSON.stringify(data).replace('{"Node":', '[');
newValue = newValue.substring(0,newValue.length - 1);
newValue+="]";
const menu=JSON.parse(newValue);
this.nodes = menu;
});
}
}