0
我在menu
模塊內部有一個MenuComponent
,我想在另一個模塊的AppComponent
中調用該組件的getMenu(path:string)
方法。如果他們在不同的模塊中,如何從另一個組件調用組件的方法?
這是我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 => {
// Read the result field from the 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;
});
}
}