角向其他组件共享navbarComponent

时间:2020-03-30 16:18:33

标签: angular navbar file-structure

我问我如何与仪表板组件和仪表板组件内的所有组件(如课程组件)共享导航菜单仪表板组件(在共享/布局内部),我有一个带有路由功能的仪表板组件模块。

仪表板模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { DashboardRoutingModule } from './dashboard-routing.module';
import { CoursesComponent } from './courses/courses.component';


@NgModule({
declarations: [CoursesComponent],
imports: [
CommonModule,
DashboardRoutingModule
]
})
export class DashboardModule { }

我在AppModule中声明了DashboardModule:

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以在DashboardComponent.html中进行以下操作

<nav-menu-dashboard #navigation></nav-menu-dashboard>

在DashboardComponent.ts中,添加以下内容:

@ViewChild('navigation', {static: false}) navigationComponent: NavMenuDashboardComponent;

您可以通过实现ViewChild方法来访问navigationComponent内部的方法和其他属性。