我想要来自组件的函数调用。
应用程序组件.html
<div class="side">
<app-menu></app-menu>
</div>
<div class="page">
<router-outlet></router-outlet>
</div>
app.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
如何<app-menu></app-menu>
在函数中调用 ' '?
应用程序菜单(menu.component.ts)
import { Component } from '@angular/core';
@Component({
...
})
export class MenuComponent {
addItem(index: number, heading: string, route: string): void {
}
groups: Array<any> = [];
}
不确定你想完成什么。我猜
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild(MenuComponent) menu:MenuComponent;
title = 'app works!';
// can't be called before the `ngAfterViewInit()` lifecycle callback.
foo() {
this.menu.addItem(1, "heading foo", "some route");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句